vite 6.2.0 → 6.2.2
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/bin/vite.js +9 -0
- package/client.d.ts +5 -0
- package/dist/node/chunks/{dep-ByPKlqZ5.js → dep-B0fRCRkQ.js} +1769 -1741
- package/dist/node/chunks/{dep-zaPmCqbl.js → dep-BL6Xg-kE.js} +1 -1
- package/dist/node/chunks/{dep-F-Bfqht7.js → dep-dLifoI9c.js} +1 -1
- package/dist/node/cli.js +6 -6
- package/dist/node/index.js +3 -3
- package/dist/node/module-runner.js +1 -1
- package/dist/node-cjs/publicUtils.cjs +1 -1
- package/package.json +7 -7
@@ -8,7 +8,7 @@ import { performance as performance$1 } from 'node:perf_hooks';
|
|
8
8
|
import require$$0$6, { createRequire as createRequire$1, builtinModules } from 'node:module';
|
9
9
|
import crypto$2 from 'node:crypto';
|
10
10
|
import esbuild, { transform as transform$1, formatMessages, build as build$b } from 'esbuild';
|
11
|
-
import { CLIENT_ENTRY, wildcardHosts, loopbackHosts, OPTIMIZABLE_ENTRY_RE, FS_PREFIX, CLIENT_PUBLIC_PATH, ENV_PUBLIC_PATH, DEFAULT_ASSETS_INLINE_LIMIT,
|
11
|
+
import { CLIENT_ENTRY, wildcardHosts, loopbackHosts, OPTIMIZABLE_ENTRY_RE, FS_PREFIX, CLIENT_PUBLIC_PATH, ENV_PUBLIC_PATH, DEFAULT_ASSETS_INLINE_LIMIT, SPECIAL_QUERY_RE, KNOWN_ASSET_TYPES, JS_TYPES_RE, CSS_LANGS_RE, METADATA_FILENAME, ESBUILD_MODULES_TARGET, ENV_ENTRY, DEP_VERSION_RE, DEV_PROD_CONDITION, ERR_OPTIMIZE_DEPS_PROCESSING_ERROR, ERR_FILE_NOT_FOUND_IN_OPTIMIZED_DEP_DIR, VITE_PACKAGE_DIR, defaultAllowedOrigins, DEFAULT_DEV_PORT, CLIENT_DIR, VERSION, ROLLUP_HOOKS, DEFAULT_PREVIEW_PORT, DEFAULT_ASSETS_RE, DEFAULT_CONFIG_FILES, DEFAULT_CLIENT_CONDITIONS, DEFAULT_SERVER_CONDITIONS, DEFAULT_CLIENT_MAIN_FIELDS, DEFAULT_SERVER_MAIN_FIELDS } from '../constants.js';
|
12
12
|
import require$$0$2, { posix, isAbsolute, resolve as resolve$3, win32, relative as relative$1, join, dirname as dirname$1, extname, basename as basename$1, sep } from 'path';
|
13
13
|
import require$$0$3, { statSync, existsSync, readFileSync, readdirSync } from 'fs';
|
14
14
|
import childProcess$2, { exec, execFile, execSync } from 'node:child_process';
|
@@ -28,10 +28,10 @@ import net$1 from 'node:net';
|
|
28
28
|
import { promises } from 'node:dns';
|
29
29
|
import { ModuleRunner, ESModulesEvaluator } from 'vite/module-runner';
|
30
30
|
import { parseAstAsync, parseAst } from 'rollup/parseAst';
|
31
|
+
import { Buffer as Buffer$1 } from 'node:buffer';
|
31
32
|
import { createRequire as createRequire$2 } from 'module';
|
32
33
|
import readline from 'node:readline';
|
33
34
|
import process$1 from 'node:process';
|
34
|
-
import { Buffer as Buffer$1 } from 'node:buffer';
|
35
35
|
import { EventEmitter as EventEmitter$4 } from 'node:events';
|
36
36
|
import require$$3 from 'crypto';
|
37
37
|
import assert$1 from 'node:assert';
|
@@ -5066,7 +5066,7 @@ function isReference(node, parent) {
|
|
5066
5066
|
return false;
|
5067
5067
|
}
|
5068
5068
|
|
5069
|
-
var version$2 = "28.0.
|
5069
|
+
var version$2 = "28.0.3";
|
5070
5070
|
var peerDependencies = {
|
5071
5071
|
rollup: "^2.68.0||^3.0.0||^4.0.0"
|
5072
5072
|
};
|
@@ -5431,7 +5431,7 @@ export function getDefaultExportFromNamespaceIfNotNamed (n) {
|
|
5431
5431
|
}
|
5432
5432
|
|
5433
5433
|
export function getAugmentedNamespace(n) {
|
5434
|
-
if (n
|
5434
|
+
if (Object.prototype.hasOwnProperty.call(n, '__esModule')) return n;
|
5435
5435
|
var f = n.default;
|
5436
5436
|
if (typeof f == "function") {
|
5437
5437
|
var a = function a () {
|
@@ -10154,6 +10154,7 @@ function combineSourcemaps(filename, sourcemapList) {
|
|
10154
10154
|
}
|
10155
10155
|
return newSourcemaps;
|
10156
10156
|
});
|
10157
|
+
const escapedFilename = escapeToLinuxLikePath(filename);
|
10157
10158
|
let map;
|
10158
10159
|
let mapIndex = 1;
|
10159
10160
|
const useArrayInterface = sourcemapList.slice(0, -1).find((m) => m.sources.length !== 1) === void 0;
|
@@ -10161,12 +10162,11 @@ function combineSourcemaps(filename, sourcemapList) {
|
|
10161
10162
|
map = remapping(sourcemapList, () => null);
|
10162
10163
|
} else {
|
10163
10164
|
map = remapping(sourcemapList[0], function loader(sourcefile) {
|
10164
|
-
|
10165
|
-
|
10166
|
-
|
10167
|
-
return
|
10165
|
+
if (sourcefile === escapedFilename && sourcemapList[mapIndex]) {
|
10166
|
+
return sourcemapList[mapIndex++];
|
10167
|
+
} else {
|
10168
|
+
return null;
|
10168
10169
|
}
|
10169
|
-
return null;
|
10170
10170
|
});
|
10171
10171
|
}
|
10172
10172
|
if (!map.file) {
|
@@ -10448,7 +10448,7 @@ function normalizeSingleAlias({
|
|
10448
10448
|
replacement,
|
10449
10449
|
customResolver
|
10450
10450
|
}) {
|
10451
|
-
if (typeof find === "string" && find
|
10451
|
+
if (typeof find === "string" && find.endsWith("/") && replacement.endsWith("/")) {
|
10452
10452
|
find = find.slice(0, find.length - 1);
|
10453
10453
|
replacement = replacement.slice(0, replacement.length - 1);
|
10454
10454
|
}
|
@@ -10500,7 +10500,7 @@ function joinUrlSegments(a, b) {
|
|
10500
10500
|
if (!a || !b) {
|
10501
10501
|
return a || b || "";
|
10502
10502
|
}
|
10503
|
-
if (a
|
10503
|
+
if (a.endsWith("/")) {
|
10504
10504
|
a = a.substring(0, a.length - 1);
|
10505
10505
|
}
|
10506
10506
|
if (b[0] !== "/") {
|
@@ -10880,9 +10880,9 @@ function buildReporterPlugin(config) {
|
|
10880
10880
|
return {
|
10881
10881
|
name: chunk.fileName,
|
10882
10882
|
group: "JS",
|
10883
|
-
size: chunk.code
|
10883
|
+
size: Buffer.byteLength(chunk.code),
|
10884
10884
|
compressedSize: await getCompressedSize(chunk.code),
|
10885
|
-
mapSize: chunk.map ? chunk.map.toString()
|
10885
|
+
mapSize: chunk.map ? Buffer.byteLength(chunk.map.toString()) : null
|
10886
10886
|
};
|
10887
10887
|
} else {
|
10888
10888
|
if (chunk.fileName.endsWith(".map")) return null;
|
@@ -10891,7 +10891,7 @@ function buildReporterPlugin(config) {
|
|
10891
10891
|
return {
|
10892
10892
|
name: chunk.fileName,
|
10893
10893
|
group: isCSS ? "CSS" : "Assets",
|
10894
|
-
size: chunk.source
|
10894
|
+
size: Buffer.byteLength(chunk.source),
|
10895
10895
|
mapSize: null,
|
10896
10896
|
// Rollup doesn't support CSS maps?
|
10897
10897
|
compressedSize: isCompressible ? await getCompressedSize(chunk.source) : null
|
@@ -15467,6 +15467,94 @@ function alias$1(options = {}) {
|
|
15467
15467
|
};
|
15468
15468
|
}
|
15469
15469
|
|
15470
|
+
const jsonExtRE = /\.json(?:$|\?)(?!commonjs-(?:proxy|external))/;
|
15471
|
+
const jsonObjRE = /^\s*\{/;
|
15472
|
+
const jsonLangs = `\\.(?:json|json5)(?:$|\\?)`;
|
15473
|
+
const jsonLangRE = new RegExp(jsonLangs);
|
15474
|
+
const isJSONRequest = (request) => jsonLangRE.test(request);
|
15475
|
+
function jsonPlugin(options, isBuild) {
|
15476
|
+
return {
|
15477
|
+
name: "vite:json",
|
15478
|
+
transform(json, id) {
|
15479
|
+
if (!jsonExtRE.test(id)) return null;
|
15480
|
+
if (SPECIAL_QUERY_RE.test(id)) return null;
|
15481
|
+
if (inlineRE$2.test(id) || noInlineRE.test(id)) {
|
15482
|
+
this.warn(
|
15483
|
+
`
|
15484
|
+
Using ?inline or ?no-inline for JSON imports will have no effect.
|
15485
|
+
Please use ?url&inline or ?url&no-inline to control JSON file inlining behavior.
|
15486
|
+
`
|
15487
|
+
);
|
15488
|
+
}
|
15489
|
+
json = stripBomTag(json);
|
15490
|
+
try {
|
15491
|
+
if (options.stringify !== false) {
|
15492
|
+
if (options.namedExports && jsonObjRE.test(json)) {
|
15493
|
+
const parsed = JSON.parse(json);
|
15494
|
+
const keys = Object.keys(parsed);
|
15495
|
+
let code = "";
|
15496
|
+
let defaultObjectCode = "{\n";
|
15497
|
+
for (const key of keys) {
|
15498
|
+
if (key === makeLegalIdentifier(key)) {
|
15499
|
+
code += `export const ${key} = ${serializeValue(parsed[key])};
|
15500
|
+
`;
|
15501
|
+
defaultObjectCode += ` ${key},
|
15502
|
+
`;
|
15503
|
+
} else {
|
15504
|
+
defaultObjectCode += ` ${JSON.stringify(key)}: ${serializeValue(parsed[key])},
|
15505
|
+
`;
|
15506
|
+
}
|
15507
|
+
}
|
15508
|
+
defaultObjectCode += "}";
|
15509
|
+
code += `export default ${defaultObjectCode};
|
15510
|
+
`;
|
15511
|
+
return {
|
15512
|
+
code,
|
15513
|
+
map: { mappings: "" }
|
15514
|
+
};
|
15515
|
+
}
|
15516
|
+
if (options.stringify === true || // use 10kB as a threshold for 'auto'
|
15517
|
+
// https://v8.dev/blog/cost-of-javascript-2019#:~:text=A%20good%20rule%20of%20thumb%20is%20to%20apply%20this%20technique%20for%20objects%20of%2010%20kB%20or%20larger
|
15518
|
+
json.length > 10 * 1e3) {
|
15519
|
+
if (isBuild) {
|
15520
|
+
json = JSON.stringify(JSON.parse(json));
|
15521
|
+
}
|
15522
|
+
return {
|
15523
|
+
code: `export default /* #__PURE__ */ JSON.parse(${JSON.stringify(json)})`,
|
15524
|
+
map: { mappings: "" }
|
15525
|
+
};
|
15526
|
+
}
|
15527
|
+
}
|
15528
|
+
return {
|
15529
|
+
code: dataToEsm(JSON.parse(json), {
|
15530
|
+
preferConst: true,
|
15531
|
+
namedExports: options.namedExports
|
15532
|
+
}),
|
15533
|
+
map: { mappings: "" }
|
15534
|
+
};
|
15535
|
+
} catch (e) {
|
15536
|
+
const position = extractJsonErrorPosition(e.message, json.length);
|
15537
|
+
const msg = position ? `, invalid JSON syntax found at position ${position}` : `.`;
|
15538
|
+
this.error(`Failed to parse JSON file` + msg, position);
|
15539
|
+
}
|
15540
|
+
}
|
15541
|
+
};
|
15542
|
+
}
|
15543
|
+
function serializeValue(value) {
|
15544
|
+
const valueAsString = JSON.stringify(value);
|
15545
|
+
if (typeof value === "object" && value != null && valueAsString.length > 10 * 1e3) {
|
15546
|
+
return `/* #__PURE__ */ JSON.parse(${JSON.stringify(valueAsString)})`;
|
15547
|
+
}
|
15548
|
+
return valueAsString;
|
15549
|
+
}
|
15550
|
+
function extractJsonErrorPosition(errorMessage, inputLength) {
|
15551
|
+
if (errorMessage.startsWith("Unexpected end of JSON input")) {
|
15552
|
+
return inputLength - 1;
|
15553
|
+
}
|
15554
|
+
const errorMessageList = /at position (\d+)/.exec(errorMessage);
|
15555
|
+
return errorMessageList ? Math.max(parseInt(errorMessageList[1], 10) - 1, 0) : void 0;
|
15556
|
+
}
|
15557
|
+
|
15470
15558
|
function e(e,n,r){throw new Error(r?`No known conditions for "${n}" specifier in "${e}" package`:`Missing "${n}" specifier in "${e}" package`)}function n(n,i,o,f){let s,u,l=r(n,o),c=function(e){let n=new Set(["default",...e.conditions||[]]);return e.unsafe||n.add(e.require?"require":"import"),e.unsafe||n.add(e.browser?"browser":"node"),n}(f||{}),a=i[l];if(void 0===a){let e,n,r,t;for(t in i)n&&t.length<n.length||("/"===t[t.length-1]&&l.startsWith(t)?(u=l.substring(t.length),n=t):t.length>1&&(r=t.indexOf("*",1),~r&&(e=RegExp("^"+t.substring(0,r)+"(.*)"+t.substring(1+r)+"$").exec(l),e&&e[1]&&(u=e[1],n=t))));a=i[n];}return a||e(n,l),s=t(a,c),s||e(n,l,1),u&&function(e,n){let r,t=0,i=e.length,o=/[*]/g,f=/[/]$/;for(;t<i;t++)e[t]=o.test(r=e[t])?r.replace(o,n):f.test(r)?r+n:r;}(s,u),s}function r(e,n,r){if(e===n||"."===n)return ".";let t=e+"/",i=t.length,o=n.slice(0,i)===t,f=o?n.slice(i):n;return "#"===f[0]?f:"./"===f.slice(0,2)?f:"./"+f}function t(e,n,r){if(e){if("string"==typeof e)return r&&r.add(e),[e];let i,o;if(Array.isArray(e)){for(o=r||new Set,i=0;i<e.length;i++)t(e[i],n,o);if(!r&&o.size)return [...o]}else for(i in e)if(n.has(i))return t(e[i],n,r)}}function o(e,r,t){let i,o=e.exports;if(o){if("string"==typeof o)o={".":o};else for(i in o){"."!==i[0]&&(o={".":o});break}return n(e.name,o,r||".",t)}}function f(e,r,t){if(e.imports)return n(e.name,e.imports,r,t)}
|
15471
15559
|
|
15472
15560
|
const HASH_RE = /#/g;
|
@@ -16042,1155 +16130,372 @@ function hasESMSyntax(code, opts = {}) {
|
|
16042
16130
|
return ESM_RE.test(code);
|
16043
16131
|
}
|
16044
16132
|
|
16045
|
-
const
|
16046
|
-
const
|
16047
|
-
|
16048
|
-
|
16049
|
-
|
16050
|
-
|
16051
|
-
|
16052
|
-
|
16053
|
-
|
16054
|
-
|
16055
|
-
|
16056
|
-
|
16057
|
-
|
16058
|
-
|
16059
|
-
|
16060
|
-
|
16061
|
-
|
16062
|
-
|
16063
|
-
|
16064
|
-
|
16065
|
-
|
16066
|
-
|
16067
|
-
|
16068
|
-
|
16069
|
-
|
16070
|
-
|
16071
|
-
|
16072
|
-
|
16073
|
-
|
16074
|
-
|
16075
|
-
|
16076
|
-
|
16077
|
-
const
|
16078
|
-
|
16079
|
-
|
16133
|
+
const externalWithConversionNamespace = "vite:dep-pre-bundle:external-conversion";
|
16134
|
+
const convertedExternalPrefix = "vite-dep-pre-bundle-external:";
|
16135
|
+
const cjsExternalFacadeNamespace = "vite:cjs-external-facade";
|
16136
|
+
const nonFacadePrefix = "vite-cjs-external-facade:";
|
16137
|
+
const externalTypes = [
|
16138
|
+
"css",
|
16139
|
+
// supported pre-processor types
|
16140
|
+
"less",
|
16141
|
+
"sass",
|
16142
|
+
"scss",
|
16143
|
+
"styl",
|
16144
|
+
"stylus",
|
16145
|
+
"pcss",
|
16146
|
+
"postcss",
|
16147
|
+
// wasm
|
16148
|
+
"wasm",
|
16149
|
+
// known SFC types
|
16150
|
+
"vue",
|
16151
|
+
"svelte",
|
16152
|
+
"marko",
|
16153
|
+
"astro",
|
16154
|
+
"imba",
|
16155
|
+
// JSX/TSX may be configured to be compiled differently from how esbuild
|
16156
|
+
// handles it by default, so exclude them as well
|
16157
|
+
"jsx",
|
16158
|
+
"tsx",
|
16159
|
+
...KNOWN_ASSET_TYPES
|
16160
|
+
];
|
16161
|
+
function esbuildDepPlugin(environment, qualified, external) {
|
16162
|
+
const { isProduction } = environment.config;
|
16163
|
+
const { extensions } = environment.config.optimizeDeps;
|
16164
|
+
const allExternalTypes = extensions ? externalTypes.filter((type) => !extensions.includes("." + type)) : externalTypes;
|
16165
|
+
const esmPackageCache = /* @__PURE__ */ new Map();
|
16166
|
+
const cjsPackageCache = /* @__PURE__ */ new Map();
|
16167
|
+
const _resolve = createBackCompatIdResolver(environment.getTopLevelConfig(), {
|
16168
|
+
asSrc: false,
|
16169
|
+
scan: true,
|
16170
|
+
packageCache: esmPackageCache
|
16171
|
+
});
|
16172
|
+
const _resolveRequire = createBackCompatIdResolver(
|
16173
|
+
environment.getTopLevelConfig(),
|
16174
|
+
{
|
16175
|
+
asSrc: false,
|
16176
|
+
isRequire: true,
|
16177
|
+
scan: true,
|
16178
|
+
packageCache: cjsPackageCache
|
16080
16179
|
}
|
16081
|
-
|
16082
|
-
|
16083
|
-
|
16084
|
-
|
16085
|
-
|
16086
|
-
config.command === "build" ? void 0 : importer,
|
16087
|
-
resolveOptions,
|
16088
|
-
void 0,
|
16089
|
-
false
|
16090
|
-
);
|
16091
|
-
if (!resolved) {
|
16092
|
-
return false;
|
16093
|
-
}
|
16094
|
-
if (!configuredAsExternal && !isInNodeModules$1(resolved.id)) {
|
16095
|
-
return false;
|
16096
|
-
}
|
16097
|
-
return canExternalizeFile(resolved.id);
|
16098
|
-
} catch {
|
16099
|
-
debug$g?.(
|
16100
|
-
`Failed to node resolve "${id}". Skipping externalizing it by default.`
|
16101
|
-
);
|
16102
|
-
return false;
|
16180
|
+
);
|
16181
|
+
const resolve = (id, importer, kind, resolveDir) => {
|
16182
|
+
let _importer;
|
16183
|
+
{
|
16184
|
+
_importer = importer in qualified ? qualified[importer] : importer;
|
16103
16185
|
}
|
16186
|
+
const resolver = kind.startsWith("require") ? _resolveRequire : _resolve;
|
16187
|
+
return resolver(environment, id, _importer);
|
16104
16188
|
};
|
16105
|
-
|
16106
|
-
if (
|
16107
|
-
|
16108
|
-
|
16109
|
-
|
16110
|
-
|
16111
|
-
return true;
|
16112
|
-
}
|
16113
|
-
const pkgName = getNpmPackageName(id);
|
16114
|
-
if (!pkgName) {
|
16115
|
-
return isExternalizable(id, importer, false);
|
16116
|
-
}
|
16117
|
-
if (
|
16118
|
-
// A package name in ssr.external externalizes every
|
16119
|
-
// externalizable package entry
|
16120
|
-
external !== true && external.includes(pkgName)
|
16121
|
-
) {
|
16122
|
-
return isExternalizable(id, importer, true);
|
16123
|
-
}
|
16124
|
-
if (typeof noExternal === "boolean") {
|
16125
|
-
return !noExternal;
|
16189
|
+
const resolveResult = (id, resolved) => {
|
16190
|
+
if (resolved.startsWith(browserExternalId)) {
|
16191
|
+
return {
|
16192
|
+
path: id,
|
16193
|
+
namespace: "browser-external"
|
16194
|
+
};
|
16126
16195
|
}
|
16127
|
-
if (
|
16128
|
-
return
|
16196
|
+
if (resolved.startsWith(optionalPeerDepId)) {
|
16197
|
+
return {
|
16198
|
+
path: resolved,
|
16199
|
+
namespace: "optional-peer-dep"
|
16200
|
+
};
|
16129
16201
|
}
|
16130
|
-
|
16131
|
-
|
16132
|
-
}
|
16133
|
-
function createIsExternal(environment) {
|
16134
|
-
const processedIds = /* @__PURE__ */ new Map();
|
16135
|
-
const isConfiguredAsExternal2 = createIsConfiguredAsExternal(environment);
|
16136
|
-
return (id, importer) => {
|
16137
|
-
if (processedIds.has(id)) {
|
16138
|
-
return processedIds.get(id);
|
16202
|
+
if (isBuiltin(environment.config.resolve.builtins, resolved)) {
|
16203
|
+
return;
|
16139
16204
|
}
|
16140
|
-
|
16141
|
-
|
16142
|
-
|
16205
|
+
if (isExternalUrl(resolved)) {
|
16206
|
+
return {
|
16207
|
+
path: resolved,
|
16208
|
+
external: true
|
16209
|
+
};
|
16143
16210
|
}
|
16144
|
-
|
16145
|
-
|
16211
|
+
return {
|
16212
|
+
path: path$d.resolve(resolved)
|
16213
|
+
};
|
16146
16214
|
};
|
16147
|
-
}
|
16148
|
-
function canExternalizeFile(filePath) {
|
16149
|
-
const ext = path$d.extname(filePath);
|
16150
|
-
return !ext || ext === ".js" || ext === ".mjs" || ext === ".cjs";
|
16151
|
-
}
|
16152
|
-
|
16153
|
-
const normalizedClientEntry$1 = normalizePath$3(CLIENT_ENTRY);
|
16154
|
-
const normalizedEnvEntry$1 = normalizePath$3(ENV_ENTRY);
|
16155
|
-
const ERR_RESOLVE_PACKAGE_ENTRY_FAIL = "ERR_RESOLVE_PACKAGE_ENTRY_FAIL";
|
16156
|
-
const browserExternalId = "__vite-browser-external";
|
16157
|
-
const optionalPeerDepId = "__vite-optional-peer-dep";
|
16158
|
-
const subpathImportsPrefix = "#";
|
16159
|
-
const startsWithWordCharRE = /^\w/;
|
16160
|
-
const debug$f = createDebugger("vite:resolve-details", {
|
16161
|
-
onlyWhenFocused: true
|
16162
|
-
});
|
16163
|
-
function resolvePlugin(resolveOptions) {
|
16164
|
-
const { root, isProduction, asSrc, preferRelative = false } = resolveOptions;
|
16165
|
-
const rootInRoot = tryStatSync(path$d.join(root, root))?.isDirectory() ?? false;
|
16166
16215
|
return {
|
16167
|
-
name: "vite:
|
16168
|
-
|
16169
|
-
|
16170
|
-
|
16171
|
-
|
16172
|
-
}
|
16173
|
-
|
16174
|
-
|
16175
|
-
|
16176
|
-
|
16177
|
-
|
16178
|
-
|
16179
|
-
|
16180
|
-
|
16181
|
-
|
16182
|
-
|
16183
|
-
|
16184
|
-
|
16185
|
-
};
|
16186
|
-
const resolvedImports = resolveSubpathImports(id, importer, options);
|
16187
|
-
if (resolvedImports) {
|
16188
|
-
id = resolvedImports;
|
16189
|
-
if (resolveOpts.custom?.["vite:import-glob"]?.isSubImportsPattern) {
|
16190
|
-
return normalizePath$3(path$d.join(root, id));
|
16191
|
-
}
|
16192
|
-
}
|
16193
|
-
let res;
|
16194
|
-
if (asSrc && depsOptimizer?.isOptimizedDepUrl(id)) {
|
16195
|
-
const optimizedPath = id.startsWith(FS_PREFIX) ? fsPathFromId(id) : normalizePath$3(path$d.resolve(root, id.slice(1)));
|
16196
|
-
return optimizedPath;
|
16197
|
-
}
|
16198
|
-
if (asSrc && id.startsWith(FS_PREFIX)) {
|
16199
|
-
res = fsPathFromId(id);
|
16200
|
-
debug$f?.(`[@fs] ${colors$1.cyan(id)} -> ${colors$1.dim(res)}`);
|
16201
|
-
return ensureVersionQuery(res, id, options, depsOptimizer);
|
16202
|
-
}
|
16203
|
-
if (asSrc && id[0] === "/" && (rootInRoot || !id.startsWith(withTrailingSlash(root)))) {
|
16204
|
-
const fsPath = path$d.resolve(root, id.slice(1));
|
16205
|
-
if (res = tryFsResolve(fsPath, options)) {
|
16206
|
-
debug$f?.(`[url] ${colors$1.cyan(id)} -> ${colors$1.dim(res)}`);
|
16207
|
-
return ensureVersionQuery(res, id, options, depsOptimizer);
|
16208
|
-
}
|
16209
|
-
}
|
16210
|
-
if (id[0] === "." || (preferRelative || importer?.endsWith(".html")) && startsWithWordCharRE.test(id)) {
|
16211
|
-
const basedir = importer ? path$d.dirname(importer) : process.cwd();
|
16212
|
-
const fsPath = path$d.resolve(basedir, id);
|
16213
|
-
const normalizedFsPath = normalizePath$3(fsPath);
|
16214
|
-
if (depsOptimizer?.isOptimizedDepFile(normalizedFsPath)) {
|
16215
|
-
if (!options.isBuild && !DEP_VERSION_RE.test(normalizedFsPath)) {
|
16216
|
-
const browserHash = optimizedDepInfoFromFile(
|
16217
|
-
depsOptimizer.metadata,
|
16218
|
-
normalizedFsPath
|
16219
|
-
)?.browserHash;
|
16220
|
-
if (browserHash) {
|
16221
|
-
return injectQuery(normalizedFsPath, `v=${browserHash}`);
|
16222
|
-
}
|
16216
|
+
name: "vite:dep-pre-bundle",
|
16217
|
+
setup(build) {
|
16218
|
+
build.onEnd(() => {
|
16219
|
+
esmPackageCache.clear();
|
16220
|
+
cjsPackageCache.clear();
|
16221
|
+
});
|
16222
|
+
build.onResolve(
|
16223
|
+
{
|
16224
|
+
filter: new RegExp(
|
16225
|
+
`\\.(` + allExternalTypes.join("|") + `)(\\?.*)?$`
|
16226
|
+
)
|
16227
|
+
},
|
16228
|
+
async ({ path: id, importer, kind }) => {
|
16229
|
+
if (id.startsWith(convertedExternalPrefix)) {
|
16230
|
+
return {
|
16231
|
+
path: id.slice(convertedExternalPrefix.length),
|
16232
|
+
external: true
|
16233
|
+
};
|
16223
16234
|
}
|
16224
|
-
|
16225
|
-
|
16226
|
-
|
16227
|
-
return res;
|
16228
|
-
}
|
16229
|
-
if (res = tryFsResolve(fsPath, options)) {
|
16230
|
-
res = ensureVersionQuery(res, id, options, depsOptimizer);
|
16231
|
-
debug$f?.(`[relative] ${colors$1.cyan(id)} -> ${colors$1.dim(res)}`);
|
16232
|
-
if (!options.idOnly && !options.scan && options.isBuild) {
|
16233
|
-
const resPkg = findNearestPackageData(
|
16234
|
-
path$d.dirname(res),
|
16235
|
-
options.packageCache
|
16236
|
-
);
|
16237
|
-
if (resPkg) {
|
16235
|
+
const resolved = await resolve(id, importer, kind);
|
16236
|
+
if (resolved) {
|
16237
|
+
if (JS_TYPES_RE.test(resolved)) {
|
16238
16238
|
return {
|
16239
|
-
|
16240
|
-
|
16239
|
+
path: resolved,
|
16240
|
+
external: false
|
16241
|
+
};
|
16242
|
+
}
|
16243
|
+
if (kind === "require-call") {
|
16244
|
+
return {
|
16245
|
+
path: resolved,
|
16246
|
+
namespace: externalWithConversionNamespace
|
16241
16247
|
};
|
16242
16248
|
}
|
16249
|
+
return {
|
16250
|
+
path: resolved,
|
16251
|
+
external: true
|
16252
|
+
};
|
16243
16253
|
}
|
16244
|
-
return res;
|
16245
|
-
}
|
16246
|
-
}
|
16247
|
-
if (id.startsWith("file://")) {
|
16248
|
-
const { file, postfix } = splitFileAndPostfix(id);
|
16249
|
-
id = fileURLToPath$1(file) + postfix;
|
16250
|
-
}
|
16251
|
-
if (isWindows$3 && id[0] === "/") {
|
16252
|
-
const basedir = importer ? path$d.dirname(importer) : process.cwd();
|
16253
|
-
const fsPath = path$d.resolve(basedir, id);
|
16254
|
-
if (res = tryFsResolve(fsPath, options)) {
|
16255
|
-
debug$f?.(`[drive-relative] ${colors$1.cyan(id)} -> ${colors$1.dim(res)}`);
|
16256
|
-
return ensureVersionQuery(res, id, options, depsOptimizer);
|
16257
|
-
}
|
16258
|
-
}
|
16259
|
-
if (isNonDriveRelativeAbsolutePath(id) && (res = tryFsResolve(id, options))) {
|
16260
|
-
debug$f?.(`[fs] ${colors$1.cyan(id)} -> ${colors$1.dim(res)}`);
|
16261
|
-
return ensureVersionQuery(res, id, options, depsOptimizer);
|
16262
|
-
}
|
16263
|
-
if (isExternalUrl(id)) {
|
16264
|
-
return options.idOnly ? id : { id, external: true };
|
16265
|
-
}
|
16266
|
-
if (isDataUrl(id)) {
|
16267
|
-
return null;
|
16268
|
-
}
|
16269
|
-
if (bareImportRE.test(id)) {
|
16270
|
-
const external = options.externalize && options.isBuild && currentEnvironmentOptions.consumer === "server" && shouldExternalize(this.environment, id, importer);
|
16271
|
-
if (!external && asSrc && depsOptimizer && !options.scan && (res = await tryOptimizedResolve(
|
16272
|
-
depsOptimizer,
|
16273
|
-
id,
|
16274
|
-
importer,
|
16275
|
-
options.preserveSymlinks,
|
16276
|
-
options.packageCache
|
16277
|
-
))) {
|
16278
|
-
return res;
|
16279
16254
|
}
|
16280
|
-
|
16281
|
-
|
16282
|
-
|
16283
|
-
|
16284
|
-
|
16285
|
-
|
16286
|
-
|
16287
|
-
|
16255
|
+
);
|
16256
|
+
build.onLoad(
|
16257
|
+
{ filter: /./, namespace: externalWithConversionNamespace },
|
16258
|
+
(args) => {
|
16259
|
+
const modulePath = `"${convertedExternalPrefix}${args.path}"`;
|
16260
|
+
return {
|
16261
|
+
contents: isCSSRequest(args.path) && !isModuleCSSRequest(args.path) ? `import ${modulePath};` : `export { default } from ${modulePath};export * from ${modulePath};`,
|
16262
|
+
loader: "js"
|
16263
|
+
};
|
16288
16264
|
}
|
16289
|
-
|
16290
|
-
|
16265
|
+
);
|
16266
|
+
function resolveEntry(id) {
|
16267
|
+
const flatId = flattenId(id);
|
16268
|
+
if (flatId in qualified) {
|
16269
|
+
return {
|
16270
|
+
path: qualified[flatId]
|
16271
|
+
};
|
16291
16272
|
}
|
16292
|
-
|
16293
|
-
|
16294
|
-
|
16295
|
-
|
16296
|
-
|
16297
|
-
|
16298
|
-
|
16299
|
-
|
16300
|
-
|
16301
|
-
)}"`;
|
16302
|
-
}
|
16303
|
-
message += `. Consider adding it to environments.${this.environment.name}.external if it is intended.`;
|
16304
|
-
this.warn(message);
|
16273
|
+
}
|
16274
|
+
build.onResolve(
|
16275
|
+
{ filter: /^[\w@][^:]/ },
|
16276
|
+
async ({ path: id, importer, kind }) => {
|
16277
|
+
if (moduleListContains(external, id)) {
|
16278
|
+
return {
|
16279
|
+
path: id,
|
16280
|
+
external: true
|
16281
|
+
};
|
16305
16282
|
}
|
16306
|
-
|
16307
|
-
|
16308
|
-
|
16309
|
-
|
16310
|
-
|
16311
|
-
|
16312
|
-
if (importer) {
|
16313
|
-
message += ` imported from "${path$d.relative(
|
16314
|
-
process.cwd(),
|
16315
|
-
importer
|
16316
|
-
)}"`;
|
16283
|
+
let entry;
|
16284
|
+
if (!importer) {
|
16285
|
+
if (entry = resolveEntry(id)) return entry;
|
16286
|
+
const aliased = await _resolve(environment, id, void 0, true);
|
16287
|
+
if (aliased && (entry = resolveEntry(aliased))) {
|
16288
|
+
return entry;
|
16317
16289
|
}
|
16318
|
-
message += `. Consider disabling environments.${this.environment.name}.noExternal or remove the built-in dependency.`;
|
16319
|
-
this.error(message);
|
16320
16290
|
}
|
16321
|
-
|
16322
|
-
|
16323
|
-
|
16324
|
-
);
|
16325
|
-
} else if (isProduction) {
|
16326
|
-
this.warn(
|
16327
|
-
`Module "${id}" has been externalized for browser compatibility, imported by "${importer}". See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.`
|
16328
|
-
);
|
16291
|
+
const resolved = await resolve(id, importer, kind);
|
16292
|
+
if (resolved) {
|
16293
|
+
return resolveResult(id, resolved);
|
16329
16294
|
}
|
16330
|
-
return isProduction ? browserExternalId : `${browserExternalId}:${id}`;
|
16331
16295
|
}
|
16332
|
-
|
16333
|
-
|
16334
|
-
|
16335
|
-
|
16336
|
-
|
16337
|
-
|
16338
|
-
|
16339
|
-
|
16340
|
-
|
16341
|
-
|
16342
|
-
|
16343
|
-
|
16344
|
-
|
16345
|
-
|
16346
|
-
|
16347
|
-
|
16348
|
-
|
16349
|
-
|
16350
|
-
|
16351
|
-
|
16352
|
-
|
16353
|
-
|
16354
|
-
|
16355
|
-
|
16356
|
-
|
16357
|
-
|
16358
|
-
}
|
16359
|
-
|
16360
|
-
|
16361
|
-
|
16362
|
-
|
16363
|
-
|
16364
|
-
|
16365
|
-
|
16366
|
-
|
16367
|
-
pkgData.data,
|
16368
|
-
idWithoutPostfix,
|
16369
|
-
options,
|
16370
|
-
"imports"
|
16371
|
-
);
|
16372
|
-
if (importsPath?.[0] === ".") {
|
16373
|
-
importsPath = path$d.relative(basedir, path$d.join(pkgData.dir, importsPath));
|
16374
|
-
if (importsPath[0] !== ".") {
|
16375
|
-
importsPath = `./${importsPath}`;
|
16376
|
-
}
|
16377
|
-
}
|
16378
|
-
return importsPath + postfix;
|
16379
|
-
}
|
16380
|
-
function ensureVersionQuery(resolved, id, options, depsOptimizer) {
|
16381
|
-
if (!options.isBuild && !options.scan && depsOptimizer && !(resolved === normalizedClientEntry$1 || resolved === normalizedEnvEntry$1)) {
|
16382
|
-
const isNodeModule = isInNodeModules$1(id) || isInNodeModules$1(resolved);
|
16383
|
-
if (isNodeModule && !DEP_VERSION_RE.test(resolved)) {
|
16384
|
-
const versionHash = depsOptimizer.metadata.browserHash;
|
16385
|
-
if (versionHash && isOptimizable(resolved, depsOptimizer.options)) {
|
16386
|
-
resolved = injectQuery(resolved, `v=${versionHash}`);
|
16387
|
-
}
|
16388
|
-
}
|
16389
|
-
}
|
16390
|
-
return resolved;
|
16391
|
-
}
|
16392
|
-
function tryFsResolve(fsPath, options, tryIndex = true, skipPackageJson = false) {
|
16393
|
-
const hashIndex = fsPath.indexOf("#");
|
16394
|
-
if (hashIndex >= 0 && isInNodeModules$1(fsPath)) {
|
16395
|
-
const queryIndex = fsPath.indexOf("?");
|
16396
|
-
if (queryIndex < 0 || queryIndex > hashIndex) {
|
16397
|
-
const file2 = queryIndex > hashIndex ? fsPath.slice(0, queryIndex) : fsPath;
|
16398
|
-
const res2 = tryCleanFsResolve(file2, options, tryIndex, skipPackageJson);
|
16399
|
-
if (res2) return res2 + fsPath.slice(file2.length);
|
16400
|
-
}
|
16401
|
-
}
|
16402
|
-
const { file, postfix } = splitFileAndPostfix(fsPath);
|
16403
|
-
const res = tryCleanFsResolve(file, options, tryIndex, skipPackageJson);
|
16404
|
-
if (res) return res + postfix;
|
16405
|
-
}
|
16406
|
-
const knownTsOutputRE = /\.(?:js|mjs|cjs|jsx)$/;
|
16407
|
-
const isPossibleTsOutput = (url) => knownTsOutputRE.test(url);
|
16408
|
-
function tryCleanFsResolve(file, options, tryIndex = true, skipPackageJson = false) {
|
16409
|
-
const { tryPrefix, extensions, preserveSymlinks } = options;
|
16410
|
-
const fileResult = tryResolveRealFileOrType(file, options.preserveSymlinks);
|
16411
|
-
if (fileResult?.path) return fileResult.path;
|
16412
|
-
let res;
|
16413
|
-
const possibleJsToTs = isPossibleTsOutput(file);
|
16414
|
-
if (possibleJsToTs || options.extensions.length || tryPrefix) {
|
16415
|
-
const dirPath = path$d.dirname(file);
|
16416
|
-
if (isDirectory(dirPath)) {
|
16417
|
-
if (possibleJsToTs) {
|
16418
|
-
const fileExt = path$d.extname(file);
|
16419
|
-
const fileName = file.slice(0, -fileExt.length);
|
16420
|
-
if (res = tryResolveRealFile(
|
16421
|
-
fileName + fileExt.replace("js", "ts"),
|
16422
|
-
preserveSymlinks
|
16423
|
-
))
|
16424
|
-
return res;
|
16425
|
-
if (fileExt === ".js" && (res = tryResolveRealFile(fileName + ".tsx", preserveSymlinks)))
|
16426
|
-
return res;
|
16427
|
-
}
|
16428
|
-
if (res = tryResolveRealFileWithExtensions(
|
16429
|
-
file,
|
16430
|
-
extensions,
|
16431
|
-
preserveSymlinks
|
16432
|
-
))
|
16433
|
-
return res;
|
16434
|
-
if (tryPrefix) {
|
16435
|
-
const prefixed = `${dirPath}/${options.tryPrefix}${path$d.basename(file)}`;
|
16436
|
-
if (res = tryResolveRealFile(prefixed, preserveSymlinks)) return res;
|
16437
|
-
if (res = tryResolveRealFileWithExtensions(
|
16438
|
-
prefixed,
|
16439
|
-
extensions,
|
16440
|
-
preserveSymlinks
|
16441
|
-
))
|
16442
|
-
return res;
|
16443
|
-
}
|
16296
|
+
);
|
16297
|
+
build.onLoad(
|
16298
|
+
{ filter: /.*/, namespace: "browser-external" },
|
16299
|
+
({ path: path2 }) => {
|
16300
|
+
if (isProduction) {
|
16301
|
+
return {
|
16302
|
+
contents: "module.exports = {}"
|
16303
|
+
};
|
16304
|
+
} else {
|
16305
|
+
return {
|
16306
|
+
// Return in CJS to intercept named imports. Use `Object.create` to
|
16307
|
+
// create the Proxy in the prototype to workaround esbuild issue. Why?
|
16308
|
+
//
|
16309
|
+
// In short, esbuild cjs->esm flow:
|
16310
|
+
// 1. Create empty object using `Object.create(Object.getPrototypeOf(module.exports))`.
|
16311
|
+
// 2. Assign props of `module.exports` to the object.
|
16312
|
+
// 3. Return object for ESM use.
|
16313
|
+
//
|
16314
|
+
// If we do `module.exports = new Proxy({}, {})`, step 1 returns empty object,
|
16315
|
+
// step 2 does nothing as there's no props for `module.exports`. The final object
|
16316
|
+
// is just an empty object.
|
16317
|
+
//
|
16318
|
+
// Creating the Proxy in the prototype satisfies step 1 immediately, which means
|
16319
|
+
// the returned object is a Proxy that we can intercept.
|
16320
|
+
//
|
16321
|
+
// Note: Skip keys that are accessed by esbuild and browser devtools.
|
16322
|
+
contents: `module.exports = Object.create(new Proxy({}, {
|
16323
|
+
get(_, key) {
|
16324
|
+
if (
|
16325
|
+
key !== '__esModule' &&
|
16326
|
+
key !== '__proto__' &&
|
16327
|
+
key !== 'constructor' &&
|
16328
|
+
key !== 'splice'
|
16329
|
+
) {
|
16330
|
+
console.warn(\`Module "${path2}" has been externalized for browser compatibility. Cannot access "${path2}.\${key}" in client code. See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.\`)
|
16444
16331
|
}
|
16445
16332
|
}
|
16446
|
-
|
16447
|
-
|
16448
|
-
if (!skipPackageJson) {
|
16449
|
-
let pkgPath = `${dirPath}/package.json`;
|
16450
|
-
try {
|
16451
|
-
if (fs__default.existsSync(pkgPath)) {
|
16452
|
-
if (!options.preserveSymlinks) {
|
16453
|
-
pkgPath = safeRealpathSync(pkgPath);
|
16333
|
+
}))`
|
16334
|
+
};
|
16454
16335
|
}
|
16455
|
-
const pkg = loadPackageData(pkgPath);
|
16456
|
-
return resolvePackageEntry(dirPath, pkg, options);
|
16457
16336
|
}
|
16458
|
-
|
16459
|
-
|
16460
|
-
|
16461
|
-
|
16462
|
-
|
16463
|
-
|
16464
|
-
|
16465
|
-
|
16466
|
-
|
16467
|
-
|
16468
|
-
|
16469
|
-
|
16470
|
-
|
16471
|
-
|
16472
|
-
|
16473
|
-
|
16474
|
-
))
|
16475
|
-
return res;
|
16337
|
+
);
|
16338
|
+
build.onLoad(
|
16339
|
+
{ filter: /.*/, namespace: "optional-peer-dep" },
|
16340
|
+
({ path: path2 }) => {
|
16341
|
+
if (isProduction) {
|
16342
|
+
return {
|
16343
|
+
contents: "module.exports = {}"
|
16344
|
+
};
|
16345
|
+
} else {
|
16346
|
+
const [, peerDep, parentDep] = path2.split(":");
|
16347
|
+
return {
|
16348
|
+
contents: `throw new Error(\`Could not resolve "${peerDep}" imported by "${parentDep}". Is it installed?\`)`
|
16349
|
+
};
|
16350
|
+
}
|
16351
|
+
}
|
16352
|
+
);
|
16476
16353
|
}
|
16477
|
-
}
|
16354
|
+
};
|
16478
16355
|
}
|
16479
|
-
|
16480
|
-
|
16481
|
-
|
16482
|
-
|
16483
|
-
|
16484
|
-
|
16485
|
-
|
16486
|
-
|
16487
|
-
|
16488
|
-
|
16489
|
-
|
16490
|
-
|
16491
|
-
|
16492
|
-
|
16493
|
-
let selfPkg = null;
|
16494
|
-
if (!isModuleBuiltin(id) && !id.includes("\0") && bareImportRE.test(id)) {
|
16495
|
-
const selfPackageData = findNearestPackageData(basedir, packageCache);
|
16496
|
-
selfPkg = selfPackageData?.data.exports && selfPackageData.data.name === pkgId ? selfPackageData : null;
|
16497
|
-
}
|
16498
|
-
const pkg = selfPkg || resolvePackageData(pkgId, basedir, preserveSymlinks, packageCache);
|
16499
|
-
if (!pkg) {
|
16500
|
-
if (basedir !== root && // root has no peer dep
|
16501
|
-
!isModuleBuiltin(id) && !id.includes("\0") && bareImportRE.test(id)) {
|
16502
|
-
const mainPkg = findNearestMainPackageData(basedir, packageCache)?.data;
|
16503
|
-
if (mainPkg) {
|
16504
|
-
const pkgName = getNpmPackageName(id);
|
16505
|
-
if (pkgName != null && mainPkg.peerDependencies?.[pkgName] && mainPkg.peerDependenciesMeta?.[pkgName]?.optional) {
|
16356
|
+
const matchesEntireLine = (text) => `^${escapeRegex(text)}$`;
|
16357
|
+
function esbuildCjsExternalPlugin(externals, platform) {
|
16358
|
+
return {
|
16359
|
+
name: "cjs-external",
|
16360
|
+
setup(build) {
|
16361
|
+
const filter = new RegExp(externals.map(matchesEntireLine).join("|"));
|
16362
|
+
build.onResolve({ filter: new RegExp(`^${nonFacadePrefix}`) }, (args) => {
|
16363
|
+
return {
|
16364
|
+
path: args.path.slice(nonFacadePrefix.length),
|
16365
|
+
external: true
|
16366
|
+
};
|
16367
|
+
});
|
16368
|
+
build.onResolve({ filter }, (args) => {
|
16369
|
+
if (args.kind === "require-call" && platform !== "node") {
|
16506
16370
|
return {
|
16507
|
-
|
16371
|
+
path: args.path,
|
16372
|
+
namespace: cjsExternalFacadeNamespace
|
16508
16373
|
};
|
16509
16374
|
}
|
16510
|
-
|
16511
|
-
|
16512
|
-
|
16513
|
-
|
16514
|
-
|
16515
|
-
|
16516
|
-
|
16517
|
-
|
16518
|
-
|
16519
|
-
|
16520
|
-
|
16521
|
-
|
16522
|
-
|
16523
|
-
}
|
16524
|
-
if (!canExternalizeFile(resolved2.id)) {
|
16525
|
-
return resolved2;
|
16526
|
-
}
|
16527
|
-
let resolvedId = id;
|
16528
|
-
if (deepMatch && !pkg.data.exports && path$d.extname(id) !== path$d.extname(resolved2.id)) {
|
16529
|
-
const index = resolved2.id.indexOf(id);
|
16530
|
-
if (index > -1) {
|
16531
|
-
resolvedId = resolved2.id.slice(index);
|
16532
|
-
debug$f?.(
|
16533
|
-
`[processResult] ${colors$1.cyan(id)} -> ${colors$1.dim(resolvedId)}`
|
16534
|
-
);
|
16535
|
-
}
|
16375
|
+
return {
|
16376
|
+
path: args.path,
|
16377
|
+
external: true
|
16378
|
+
};
|
16379
|
+
});
|
16380
|
+
build.onLoad(
|
16381
|
+
{ filter: /.*/, namespace: cjsExternalFacadeNamespace },
|
16382
|
+
(args) => ({
|
16383
|
+
contents: `import * as m from ${JSON.stringify(
|
16384
|
+
nonFacadePrefix + args.path
|
16385
|
+
)};module.exports = m;`
|
16386
|
+
})
|
16387
|
+
);
|
16536
16388
|
}
|
16537
|
-
return { ...resolved2, id: resolvedId, external: true };
|
16538
16389
|
};
|
16539
|
-
if (!options.idOnly && (!options.scan && isBuild || externalize)) {
|
16540
|
-
return processResult({
|
16541
|
-
id: resolved,
|
16542
|
-
moduleSideEffects: pkg.hasSideEffects(resolved)
|
16543
|
-
});
|
16544
|
-
}
|
16545
|
-
if (!isInNodeModules$1(resolved) || // linked
|
16546
|
-
!depsOptimizer || // resolving before listening to the server
|
16547
|
-
options.scan) {
|
16548
|
-
return { id: resolved };
|
16549
|
-
}
|
16550
|
-
const isJsType = isOptimizable(resolved, depsOptimizer.options);
|
16551
|
-
const exclude = depsOptimizer.options.exclude;
|
16552
|
-
const skipOptimization = depsOptimizer.options.noDiscovery || !isJsType || importer && isInNodeModules$1(importer) || exclude?.includes(pkgId) || exclude?.includes(id) || SPECIAL_QUERY_RE.test(resolved);
|
16553
|
-
if (skipOptimization) {
|
16554
|
-
const versionHash = depsOptimizer.metadata.browserHash;
|
16555
|
-
if (versionHash && isJsType) {
|
16556
|
-
resolved = injectQuery(resolved, `v=${versionHash}`);
|
16557
|
-
}
|
16558
|
-
} else {
|
16559
|
-
const optimizedInfo = depsOptimizer.registerMissingImport(id, resolved);
|
16560
|
-
resolved = depsOptimizer.getOptimizedDepId(optimizedInfo);
|
16561
|
-
}
|
16562
|
-
return { id: resolved };
|
16563
16390
|
}
|
16564
|
-
|
16565
|
-
|
16566
|
-
|
16567
|
-
|
16568
|
-
|
16569
|
-
|
16570
|
-
|
16571
|
-
|
16572
|
-
|
16573
|
-
|
16574
|
-
|
16575
|
-
|
16576
|
-
|
16577
|
-
|
16578
|
-
|
16579
|
-
|
16580
|
-
idPkgDir = resolvePackageData(
|
16581
|
-
pkgName,
|
16582
|
-
importer,
|
16583
|
-
preserveSymlinks,
|
16584
|
-
packageCache
|
16585
|
-
)?.dir;
|
16586
|
-
if (idPkgDir == null) break;
|
16587
|
-
idPkgDir = normalizePath$3(idPkgDir);
|
16588
|
-
}
|
16589
|
-
if (optimizedData.src.startsWith(withTrailingSlash(idPkgDir))) {
|
16590
|
-
return depsOptimizer.getOptimizedDepId(optimizedData);
|
16591
|
-
}
|
16592
|
-
}
|
16391
|
+
|
16392
|
+
const environmentColors = [
|
16393
|
+
colors$1.blue,
|
16394
|
+
colors$1.magenta,
|
16395
|
+
colors$1.green,
|
16396
|
+
colors$1.gray
|
16397
|
+
];
|
16398
|
+
function getDefaultResolvedEnvironmentOptions(config) {
|
16399
|
+
return {
|
16400
|
+
define: config.define,
|
16401
|
+
resolve: config.resolve,
|
16402
|
+
consumer: "server",
|
16403
|
+
optimizeDeps: config.optimizeDeps,
|
16404
|
+
dev: config.dev,
|
16405
|
+
build: config.build
|
16406
|
+
};
|
16593
16407
|
}
|
16594
|
-
|
16595
|
-
|
16596
|
-
|
16597
|
-
|
16598
|
-
return cached + postfix;
|
16408
|
+
class PartialEnvironment {
|
16409
|
+
name;
|
16410
|
+
getTopLevelConfig() {
|
16411
|
+
return this._topLevelConfig;
|
16599
16412
|
}
|
16600
|
-
|
16601
|
-
|
16602
|
-
|
16603
|
-
|
16413
|
+
config;
|
16414
|
+
/**
|
16415
|
+
* @deprecated use environment.config instead
|
16416
|
+
**/
|
16417
|
+
get options() {
|
16418
|
+
return this._options;
|
16419
|
+
}
|
16420
|
+
logger;
|
16421
|
+
/**
|
16422
|
+
* @internal
|
16423
|
+
*/
|
16424
|
+
_options;
|
16425
|
+
/**
|
16426
|
+
* @internal
|
16427
|
+
*/
|
16428
|
+
_topLevelConfig;
|
16429
|
+
constructor(name, topLevelConfig, options = topLevelConfig.environments[name]) {
|
16430
|
+
if (!/^[\w$]+$/.test(name)) {
|
16431
|
+
throw new Error(
|
16432
|
+
`Invalid environment name "${name}". Environment names must only contain alphanumeric characters and "$", "_".`
|
16433
|
+
);
|
16604
16434
|
}
|
16605
|
-
|
16606
|
-
|
16607
|
-
|
16608
|
-
|
16609
|
-
|
16610
|
-
|
16435
|
+
this.name = name;
|
16436
|
+
this._topLevelConfig = topLevelConfig;
|
16437
|
+
this._options = options;
|
16438
|
+
this.config = new Proxy(
|
16439
|
+
options,
|
16440
|
+
{
|
16441
|
+
get: (target, prop) => {
|
16442
|
+
if (prop === "logger") {
|
16443
|
+
return this.logger;
|
16611
16444
|
}
|
16612
|
-
|
16613
|
-
|
16614
|
-
|
16615
|
-
|
16616
|
-
}
|
16617
|
-
}
|
16618
|
-
entryPoint ||= data.main;
|
16619
|
-
const entryPoints = entryPoint ? [entryPoint] : ["index.js", "index.json", "index.node"];
|
16620
|
-
for (let entry of entryPoints) {
|
16621
|
-
let skipPackageJson = false;
|
16622
|
-
if (options.mainFields[0] === "sass" && !options.extensions.includes(path$d.extname(entry))) {
|
16623
|
-
entry = "";
|
16624
|
-
skipPackageJson = true;
|
16625
|
-
} else {
|
16626
|
-
const { browser: browserField } = data;
|
16627
|
-
if (options.mainFields.includes("browser") && isObject$2(browserField)) {
|
16628
|
-
entry = mapWithBrowserField(entry, browserField) || entry;
|
16445
|
+
if (prop in target) {
|
16446
|
+
return this._options[prop];
|
16447
|
+
}
|
16448
|
+
return this._topLevelConfig[prop];
|
16629
16449
|
}
|
16630
16450
|
}
|
16631
|
-
|
16632
|
-
|
16633
|
-
|
16634
|
-
|
16635
|
-
|
16636
|
-
|
16637
|
-
|
16638
|
-
|
16639
|
-
|
16640
|
-
|
16641
|
-
|
16642
|
-
|
16643
|
-
);
|
16644
|
-
|
16645
|
-
|
16451
|
+
);
|
16452
|
+
const environment = colors$1.dim(`(${this.name})`);
|
16453
|
+
const colorIndex = [...this.name].reduce((acc, c) => acc + c.charCodeAt(0), 0) % environmentColors.length;
|
16454
|
+
const infoColor = environmentColors[colorIndex || 0];
|
16455
|
+
this.logger = {
|
16456
|
+
get hasWarned() {
|
16457
|
+
return topLevelConfig.logger.hasWarned;
|
16458
|
+
},
|
16459
|
+
info(msg, opts) {
|
16460
|
+
return topLevelConfig.logger.info(msg, {
|
16461
|
+
...opts,
|
16462
|
+
environment: infoColor(environment)
|
16463
|
+
});
|
16464
|
+
},
|
16465
|
+
warn(msg, opts) {
|
16466
|
+
return topLevelConfig.logger.warn(msg, {
|
16467
|
+
...opts,
|
16468
|
+
environment: colors$1.yellow(environment)
|
16469
|
+
});
|
16470
|
+
},
|
16471
|
+
warnOnce(msg, opts) {
|
16472
|
+
return topLevelConfig.logger.warnOnce(msg, {
|
16473
|
+
...opts,
|
16474
|
+
environment: colors$1.yellow(environment)
|
16475
|
+
});
|
16476
|
+
},
|
16477
|
+
error(msg, opts) {
|
16478
|
+
return topLevelConfig.logger.error(msg, {
|
16479
|
+
...opts,
|
16480
|
+
environment: colors$1.red(environment)
|
16481
|
+
});
|
16482
|
+
},
|
16483
|
+
clearScreen(type) {
|
16484
|
+
return topLevelConfig.logger.clearScreen(type);
|
16485
|
+
},
|
16486
|
+
hasErrorLogged(error) {
|
16487
|
+
return topLevelConfig.logger.hasErrorLogged(error);
|
16646
16488
|
}
|
16647
|
-
}
|
16648
|
-
} catch (e) {
|
16649
|
-
packageEntryFailure(id, e.message);
|
16650
|
-
}
|
16651
|
-
packageEntryFailure(id);
|
16652
|
-
}
|
16653
|
-
function packageEntryFailure(id, details) {
|
16654
|
-
const err = new Error(
|
16655
|
-
`Failed to resolve entry for package "${id}". The package may have incorrect main/module/exports specified in its package.json` + (details ? ": " + details : ".")
|
16656
|
-
);
|
16657
|
-
err.code = ERR_RESOLVE_PACKAGE_ENTRY_FAIL;
|
16658
|
-
throw err;
|
16659
|
-
}
|
16660
|
-
function resolveExportsOrImports(pkg, key, options, type) {
|
16661
|
-
const conditions = options.conditions.map((condition) => {
|
16662
|
-
if (condition === DEV_PROD_CONDITION) {
|
16663
|
-
return options.isProduction ? "production" : "development";
|
16664
|
-
}
|
16665
|
-
return condition;
|
16666
|
-
});
|
16667
|
-
if (options.isRequire) {
|
16668
|
-
conditions.push("require");
|
16669
|
-
} else {
|
16670
|
-
conditions.push("import");
|
16489
|
+
};
|
16671
16490
|
}
|
16672
|
-
const fn = type === "imports" ? f : o;
|
16673
|
-
const result = fn(pkg, key, { conditions, unsafe: true });
|
16674
|
-
return result ? result[0] : void 0;
|
16675
16491
|
}
|
16676
|
-
|
16677
|
-
|
16678
|
-
|
16679
|
-
return cache;
|
16680
|
-
}
|
16681
|
-
let relativeId = id;
|
16682
|
-
const { exports: exportsField, browser: browserField } = data;
|
16683
|
-
if (exportsField) {
|
16684
|
-
if (isObject$2(exportsField) && !Array.isArray(exportsField)) {
|
16685
|
-
const { file, postfix } = splitFileAndPostfix(relativeId);
|
16686
|
-
const exportsId = resolveExportsOrImports(data, file, options, "exports");
|
16687
|
-
if (exportsId !== void 0) {
|
16688
|
-
relativeId = exportsId + postfix;
|
16689
|
-
} else {
|
16690
|
-
relativeId = void 0;
|
16691
|
-
}
|
16692
|
-
} else {
|
16693
|
-
relativeId = void 0;
|
16694
|
-
}
|
16695
|
-
if (!relativeId) {
|
16492
|
+
class BaseEnvironment extends PartialEnvironment {
|
16493
|
+
get plugins() {
|
16494
|
+
if (!this._plugins)
|
16696
16495
|
throw new Error(
|
16697
|
-
|
16496
|
+
`${this.name} environment.plugins called before initialized`
|
16698
16497
|
);
|
16699
|
-
|
16700
|
-
} else if (options.mainFields.includes("browser") && isObject$2(browserField)) {
|
16701
|
-
const { file, postfix } = splitFileAndPostfix(relativeId);
|
16702
|
-
const mapped = mapWithBrowserField(file, browserField);
|
16703
|
-
if (mapped) {
|
16704
|
-
relativeId = mapped + postfix;
|
16705
|
-
} else if (mapped === false) {
|
16706
|
-
setResolvedCache(id, browserExternalId, options);
|
16707
|
-
return browserExternalId;
|
16708
|
-
}
|
16709
|
-
}
|
16710
|
-
if (relativeId) {
|
16711
|
-
const resolved = tryFsResolve(
|
16712
|
-
path$d.join(dir, relativeId),
|
16713
|
-
options,
|
16714
|
-
!exportsField
|
16715
|
-
// try index only if no exports field
|
16716
|
-
);
|
16717
|
-
if (resolved) {
|
16718
|
-
debug$f?.(
|
16719
|
-
`[node/deep-import] ${colors$1.cyan(id)} -> ${colors$1.dim(resolved)}`
|
16720
|
-
);
|
16721
|
-
setResolvedCache(id, resolved, options);
|
16722
|
-
return resolved;
|
16723
|
-
}
|
16724
|
-
}
|
16725
|
-
}
|
16726
|
-
function tryResolveBrowserMapping(id, importer, options, isFilePath, externalize) {
|
16727
|
-
let res;
|
16728
|
-
const pkg = importer && findNearestPackageData(path$d.dirname(importer), options.packageCache);
|
16729
|
-
if (pkg && isObject$2(pkg.data.browser)) {
|
16730
|
-
const mapId = isFilePath ? "./" + slash$1(path$d.relative(pkg.dir, id)) : id;
|
16731
|
-
const browserMappedPath = mapWithBrowserField(mapId, pkg.data.browser);
|
16732
|
-
if (browserMappedPath) {
|
16733
|
-
if (res = bareImportRE.test(browserMappedPath) ? tryNodeResolve(
|
16734
|
-
browserMappedPath,
|
16735
|
-
importer,
|
16736
|
-
options,
|
16737
|
-
void 0,
|
16738
|
-
void 0
|
16739
|
-
)?.id : tryFsResolve(path$d.join(pkg.dir, browserMappedPath), options)) {
|
16740
|
-
debug$f?.(`[browser mapped] ${colors$1.cyan(id)} -> ${colors$1.dim(res)}`);
|
16741
|
-
let result = { id: res };
|
16742
|
-
if (options.idOnly) {
|
16743
|
-
return result;
|
16744
|
-
}
|
16745
|
-
if (!options.scan && options.isBuild) {
|
16746
|
-
const resPkg = findNearestPackageData(
|
16747
|
-
path$d.dirname(res),
|
16748
|
-
options.packageCache
|
16749
|
-
);
|
16750
|
-
if (resPkg) {
|
16751
|
-
result = {
|
16752
|
-
id: res,
|
16753
|
-
moduleSideEffects: resPkg.hasSideEffects(res)
|
16754
|
-
};
|
16755
|
-
}
|
16756
|
-
}
|
16757
|
-
return externalize ? { ...result, external: true } : result;
|
16758
|
-
}
|
16759
|
-
} else if (browserMappedPath === false) {
|
16760
|
-
return browserExternalId;
|
16761
|
-
}
|
16762
|
-
}
|
16763
|
-
}
|
16764
|
-
function tryResolveBrowserEntry(dir, data, options) {
|
16765
|
-
const browserEntry = typeof data.browser === "string" ? data.browser : isObject$2(data.browser) && data.browser["."];
|
16766
|
-
if (browserEntry) {
|
16767
|
-
if (!options.isRequire && options.mainFields.includes("module") && typeof data.module === "string" && data.module !== browserEntry) {
|
16768
|
-
const resolvedBrowserEntry = tryFsResolve(
|
16769
|
-
path$d.join(dir, browserEntry),
|
16770
|
-
options
|
16771
|
-
);
|
16772
|
-
if (resolvedBrowserEntry) {
|
16773
|
-
const content = fs__default.readFileSync(resolvedBrowserEntry, "utf-8");
|
16774
|
-
if (hasESMSyntax(content)) {
|
16775
|
-
return browserEntry;
|
16776
|
-
} else {
|
16777
|
-
return data.module;
|
16778
|
-
}
|
16779
|
-
}
|
16780
|
-
} else {
|
16781
|
-
return browserEntry;
|
16782
|
-
}
|
16783
|
-
}
|
16784
|
-
}
|
16785
|
-
function mapWithBrowserField(relativePathInPkgDir, map) {
|
16786
|
-
const normalizedPath = path$d.posix.normalize(relativePathInPkgDir);
|
16787
|
-
for (const key in map) {
|
16788
|
-
const normalizedKey = path$d.posix.normalize(key);
|
16789
|
-
if (normalizedPath === normalizedKey || equalWithoutSuffix(normalizedPath, normalizedKey, ".js") || equalWithoutSuffix(normalizedPath, normalizedKey, "/index.js")) {
|
16790
|
-
return map[key];
|
16791
|
-
}
|
16792
|
-
}
|
16793
|
-
}
|
16794
|
-
function equalWithoutSuffix(path2, key, suffix) {
|
16795
|
-
return key.endsWith(suffix) && key.slice(0, -suffix.length) === path2;
|
16796
|
-
}
|
16797
|
-
function tryResolveRealFile(file, preserveSymlinks) {
|
16798
|
-
const stat = tryStatSync(file);
|
16799
|
-
if (stat?.isFile()) return getRealPath(file, preserveSymlinks);
|
16800
|
-
}
|
16801
|
-
function tryResolveRealFileWithExtensions(filePath, extensions, preserveSymlinks) {
|
16802
|
-
for (const ext of extensions) {
|
16803
|
-
const res = tryResolveRealFile(filePath + ext, preserveSymlinks);
|
16804
|
-
if (res) return res;
|
16805
|
-
}
|
16806
|
-
}
|
16807
|
-
function tryResolveRealFileOrType(file, preserveSymlinks) {
|
16808
|
-
const fileStat = tryStatSync(file);
|
16809
|
-
if (fileStat?.isFile()) {
|
16810
|
-
return { path: getRealPath(file, preserveSymlinks), type: "file" };
|
16811
|
-
}
|
16812
|
-
if (fileStat?.isDirectory()) {
|
16813
|
-
return { type: "directory" };
|
16814
|
-
}
|
16815
|
-
return;
|
16816
|
-
}
|
16817
|
-
function getRealPath(resolved, preserveSymlinks) {
|
16818
|
-
if (!preserveSymlinks) {
|
16819
|
-
resolved = safeRealpathSync(resolved);
|
16820
|
-
}
|
16821
|
-
return normalizePath$3(resolved);
|
16822
|
-
}
|
16823
|
-
function isDirectory(path2) {
|
16824
|
-
const stat = tryStatSync(path2);
|
16825
|
-
return stat?.isDirectory() ?? false;
|
16826
|
-
}
|
16827
|
-
|
16828
|
-
const externalWithConversionNamespace = "vite:dep-pre-bundle:external-conversion";
|
16829
|
-
const convertedExternalPrefix = "vite-dep-pre-bundle-external:";
|
16830
|
-
const cjsExternalFacadeNamespace = "vite:cjs-external-facade";
|
16831
|
-
const nonFacadePrefix = "vite-cjs-external-facade:";
|
16832
|
-
const externalTypes = [
|
16833
|
-
"css",
|
16834
|
-
// supported pre-processor types
|
16835
|
-
"less",
|
16836
|
-
"sass",
|
16837
|
-
"scss",
|
16838
|
-
"styl",
|
16839
|
-
"stylus",
|
16840
|
-
"pcss",
|
16841
|
-
"postcss",
|
16842
|
-
// wasm
|
16843
|
-
"wasm",
|
16844
|
-
// known SFC types
|
16845
|
-
"vue",
|
16846
|
-
"svelte",
|
16847
|
-
"marko",
|
16848
|
-
"astro",
|
16849
|
-
"imba",
|
16850
|
-
// JSX/TSX may be configured to be compiled differently from how esbuild
|
16851
|
-
// handles it by default, so exclude them as well
|
16852
|
-
"jsx",
|
16853
|
-
"tsx",
|
16854
|
-
...KNOWN_ASSET_TYPES
|
16855
|
-
];
|
16856
|
-
function esbuildDepPlugin(environment, qualified, external) {
|
16857
|
-
const { isProduction } = environment.config;
|
16858
|
-
const { extensions } = environment.config.optimizeDeps;
|
16859
|
-
const allExternalTypes = extensions ? externalTypes.filter((type) => !extensions.includes("." + type)) : externalTypes;
|
16860
|
-
const esmPackageCache = /* @__PURE__ */ new Map();
|
16861
|
-
const cjsPackageCache = /* @__PURE__ */ new Map();
|
16862
|
-
const _resolve = createBackCompatIdResolver(environment.getTopLevelConfig(), {
|
16863
|
-
asSrc: false,
|
16864
|
-
scan: true,
|
16865
|
-
packageCache: esmPackageCache
|
16866
|
-
});
|
16867
|
-
const _resolveRequire = createBackCompatIdResolver(
|
16868
|
-
environment.getTopLevelConfig(),
|
16869
|
-
{
|
16870
|
-
asSrc: false,
|
16871
|
-
isRequire: true,
|
16872
|
-
scan: true,
|
16873
|
-
packageCache: cjsPackageCache
|
16874
|
-
}
|
16875
|
-
);
|
16876
|
-
const resolve = (id, importer, kind, resolveDir) => {
|
16877
|
-
let _importer;
|
16878
|
-
{
|
16879
|
-
_importer = importer in qualified ? qualified[importer] : importer;
|
16880
|
-
}
|
16881
|
-
const resolver = kind.startsWith("require") ? _resolveRequire : _resolve;
|
16882
|
-
return resolver(environment, id, _importer);
|
16883
|
-
};
|
16884
|
-
const resolveResult = (id, resolved) => {
|
16885
|
-
if (resolved.startsWith(browserExternalId)) {
|
16886
|
-
return {
|
16887
|
-
path: id,
|
16888
|
-
namespace: "browser-external"
|
16889
|
-
};
|
16890
|
-
}
|
16891
|
-
if (resolved.startsWith(optionalPeerDepId)) {
|
16892
|
-
return {
|
16893
|
-
path: resolved,
|
16894
|
-
namespace: "optional-peer-dep"
|
16895
|
-
};
|
16896
|
-
}
|
16897
|
-
if (isBuiltin(environment.config.resolve.builtins, resolved)) {
|
16898
|
-
return;
|
16899
|
-
}
|
16900
|
-
if (isExternalUrl(resolved)) {
|
16901
|
-
return {
|
16902
|
-
path: resolved,
|
16903
|
-
external: true
|
16904
|
-
};
|
16905
|
-
}
|
16906
|
-
return {
|
16907
|
-
path: path$d.resolve(resolved)
|
16908
|
-
};
|
16909
|
-
};
|
16910
|
-
return {
|
16911
|
-
name: "vite:dep-pre-bundle",
|
16912
|
-
setup(build) {
|
16913
|
-
build.onEnd(() => {
|
16914
|
-
esmPackageCache.clear();
|
16915
|
-
cjsPackageCache.clear();
|
16916
|
-
});
|
16917
|
-
build.onResolve(
|
16918
|
-
{
|
16919
|
-
filter: new RegExp(
|
16920
|
-
`\\.(` + allExternalTypes.join("|") + `)(\\?.*)?$`
|
16921
|
-
)
|
16922
|
-
},
|
16923
|
-
async ({ path: id, importer, kind }) => {
|
16924
|
-
if (id.startsWith(convertedExternalPrefix)) {
|
16925
|
-
return {
|
16926
|
-
path: id.slice(convertedExternalPrefix.length),
|
16927
|
-
external: true
|
16928
|
-
};
|
16929
|
-
}
|
16930
|
-
const resolved = await resolve(id, importer, kind);
|
16931
|
-
if (resolved) {
|
16932
|
-
if (JS_TYPES_RE.test(resolved)) {
|
16933
|
-
return {
|
16934
|
-
path: resolved,
|
16935
|
-
external: false
|
16936
|
-
};
|
16937
|
-
}
|
16938
|
-
if (kind === "require-call") {
|
16939
|
-
return {
|
16940
|
-
path: resolved,
|
16941
|
-
namespace: externalWithConversionNamespace
|
16942
|
-
};
|
16943
|
-
}
|
16944
|
-
return {
|
16945
|
-
path: resolved,
|
16946
|
-
external: true
|
16947
|
-
};
|
16948
|
-
}
|
16949
|
-
}
|
16950
|
-
);
|
16951
|
-
build.onLoad(
|
16952
|
-
{ filter: /./, namespace: externalWithConversionNamespace },
|
16953
|
-
(args) => {
|
16954
|
-
const modulePath = `"${convertedExternalPrefix}${args.path}"`;
|
16955
|
-
return {
|
16956
|
-
contents: isCSSRequest(args.path) && !isModuleCSSRequest(args.path) ? `import ${modulePath};` : `export { default } from ${modulePath};export * from ${modulePath};`,
|
16957
|
-
loader: "js"
|
16958
|
-
};
|
16959
|
-
}
|
16960
|
-
);
|
16961
|
-
function resolveEntry(id) {
|
16962
|
-
const flatId = flattenId(id);
|
16963
|
-
if (flatId in qualified) {
|
16964
|
-
return {
|
16965
|
-
path: qualified[flatId]
|
16966
|
-
};
|
16967
|
-
}
|
16968
|
-
}
|
16969
|
-
build.onResolve(
|
16970
|
-
{ filter: /^[\w@][^:]/ },
|
16971
|
-
async ({ path: id, importer, kind }) => {
|
16972
|
-
if (moduleListContains(external, id)) {
|
16973
|
-
return {
|
16974
|
-
path: id,
|
16975
|
-
external: true
|
16976
|
-
};
|
16977
|
-
}
|
16978
|
-
let entry;
|
16979
|
-
if (!importer) {
|
16980
|
-
if (entry = resolveEntry(id)) return entry;
|
16981
|
-
const aliased = await _resolve(environment, id, void 0, true);
|
16982
|
-
if (aliased && (entry = resolveEntry(aliased))) {
|
16983
|
-
return entry;
|
16984
|
-
}
|
16985
|
-
}
|
16986
|
-
const resolved = await resolve(id, importer, kind);
|
16987
|
-
if (resolved) {
|
16988
|
-
return resolveResult(id, resolved);
|
16989
|
-
}
|
16990
|
-
}
|
16991
|
-
);
|
16992
|
-
build.onLoad(
|
16993
|
-
{ filter: /.*/, namespace: "browser-external" },
|
16994
|
-
({ path: path2 }) => {
|
16995
|
-
if (isProduction) {
|
16996
|
-
return {
|
16997
|
-
contents: "module.exports = {}"
|
16998
|
-
};
|
16999
|
-
} else {
|
17000
|
-
return {
|
17001
|
-
// Return in CJS to intercept named imports. Use `Object.create` to
|
17002
|
-
// create the Proxy in the prototype to workaround esbuild issue. Why?
|
17003
|
-
//
|
17004
|
-
// In short, esbuild cjs->esm flow:
|
17005
|
-
// 1. Create empty object using `Object.create(Object.getPrototypeOf(module.exports))`.
|
17006
|
-
// 2. Assign props of `module.exports` to the object.
|
17007
|
-
// 3. Return object for ESM use.
|
17008
|
-
//
|
17009
|
-
// If we do `module.exports = new Proxy({}, {})`, step 1 returns empty object,
|
17010
|
-
// step 2 does nothing as there's no props for `module.exports`. The final object
|
17011
|
-
// is just an empty object.
|
17012
|
-
//
|
17013
|
-
// Creating the Proxy in the prototype satisfies step 1 immediately, which means
|
17014
|
-
// the returned object is a Proxy that we can intercept.
|
17015
|
-
//
|
17016
|
-
// Note: Skip keys that are accessed by esbuild and browser devtools.
|
17017
|
-
contents: `module.exports = Object.create(new Proxy({}, {
|
17018
|
-
get(_, key) {
|
17019
|
-
if (
|
17020
|
-
key !== '__esModule' &&
|
17021
|
-
key !== '__proto__' &&
|
17022
|
-
key !== 'constructor' &&
|
17023
|
-
key !== 'splice'
|
17024
|
-
) {
|
17025
|
-
console.warn(\`Module "${path2}" has been externalized for browser compatibility. Cannot access "${path2}.\${key}" in client code. See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.\`)
|
17026
|
-
}
|
17027
|
-
}
|
17028
|
-
}))`
|
17029
|
-
};
|
17030
|
-
}
|
17031
|
-
}
|
17032
|
-
);
|
17033
|
-
build.onLoad(
|
17034
|
-
{ filter: /.*/, namespace: "optional-peer-dep" },
|
17035
|
-
({ path: path2 }) => {
|
17036
|
-
if (isProduction) {
|
17037
|
-
return {
|
17038
|
-
contents: "module.exports = {}"
|
17039
|
-
};
|
17040
|
-
} else {
|
17041
|
-
const [, peerDep, parentDep] = path2.split(":");
|
17042
|
-
return {
|
17043
|
-
contents: `throw new Error(\`Could not resolve "${peerDep}" imported by "${parentDep}". Is it installed?\`)`
|
17044
|
-
};
|
17045
|
-
}
|
17046
|
-
}
|
17047
|
-
);
|
17048
|
-
}
|
17049
|
-
};
|
17050
|
-
}
|
17051
|
-
const matchesEntireLine = (text) => `^${escapeRegex(text)}$`;
|
17052
|
-
function esbuildCjsExternalPlugin(externals, platform) {
|
17053
|
-
return {
|
17054
|
-
name: "cjs-external",
|
17055
|
-
setup(build) {
|
17056
|
-
const filter = new RegExp(externals.map(matchesEntireLine).join("|"));
|
17057
|
-
build.onResolve({ filter: new RegExp(`^${nonFacadePrefix}`) }, (args) => {
|
17058
|
-
return {
|
17059
|
-
path: args.path.slice(nonFacadePrefix.length),
|
17060
|
-
external: true
|
17061
|
-
};
|
17062
|
-
});
|
17063
|
-
build.onResolve({ filter }, (args) => {
|
17064
|
-
if (args.kind === "require-call" && platform !== "node") {
|
17065
|
-
return {
|
17066
|
-
path: args.path,
|
17067
|
-
namespace: cjsExternalFacadeNamespace
|
17068
|
-
};
|
17069
|
-
}
|
17070
|
-
return {
|
17071
|
-
path: args.path,
|
17072
|
-
external: true
|
17073
|
-
};
|
17074
|
-
});
|
17075
|
-
build.onLoad(
|
17076
|
-
{ filter: /.*/, namespace: cjsExternalFacadeNamespace },
|
17077
|
-
(args) => ({
|
17078
|
-
contents: `import * as m from ${JSON.stringify(
|
17079
|
-
nonFacadePrefix + args.path
|
17080
|
-
)};module.exports = m;`
|
17081
|
-
})
|
17082
|
-
);
|
17083
|
-
}
|
17084
|
-
};
|
17085
|
-
}
|
17086
|
-
|
17087
|
-
const environmentColors = [
|
17088
|
-
colors$1.blue,
|
17089
|
-
colors$1.magenta,
|
17090
|
-
colors$1.green,
|
17091
|
-
colors$1.gray
|
17092
|
-
];
|
17093
|
-
function getDefaultResolvedEnvironmentOptions(config) {
|
17094
|
-
return {
|
17095
|
-
define: config.define,
|
17096
|
-
resolve: config.resolve,
|
17097
|
-
consumer: "server",
|
17098
|
-
optimizeDeps: config.optimizeDeps,
|
17099
|
-
dev: config.dev,
|
17100
|
-
build: config.build
|
17101
|
-
};
|
17102
|
-
}
|
17103
|
-
class PartialEnvironment {
|
17104
|
-
name;
|
17105
|
-
getTopLevelConfig() {
|
17106
|
-
return this._topLevelConfig;
|
17107
|
-
}
|
17108
|
-
config;
|
17109
|
-
/**
|
17110
|
-
* @deprecated use environment.config instead
|
17111
|
-
**/
|
17112
|
-
get options() {
|
17113
|
-
return this._options;
|
17114
|
-
}
|
17115
|
-
logger;
|
17116
|
-
/**
|
17117
|
-
* @internal
|
17118
|
-
*/
|
17119
|
-
_options;
|
17120
|
-
/**
|
17121
|
-
* @internal
|
17122
|
-
*/
|
17123
|
-
_topLevelConfig;
|
17124
|
-
constructor(name, topLevelConfig, options = topLevelConfig.environments[name]) {
|
17125
|
-
if (!/^[\w$]+$/.test(name)) {
|
17126
|
-
throw new Error(
|
17127
|
-
`Invalid environment name "${name}". Environment names must only contain alphanumeric characters and "$", "_".`
|
17128
|
-
);
|
17129
|
-
}
|
17130
|
-
this.name = name;
|
17131
|
-
this._topLevelConfig = topLevelConfig;
|
17132
|
-
this._options = options;
|
17133
|
-
this.config = new Proxy(
|
17134
|
-
options,
|
17135
|
-
{
|
17136
|
-
get: (target, prop) => {
|
17137
|
-
if (prop === "logger") {
|
17138
|
-
return this.logger;
|
17139
|
-
}
|
17140
|
-
if (prop in target) {
|
17141
|
-
return this._options[prop];
|
17142
|
-
}
|
17143
|
-
return this._topLevelConfig[prop];
|
17144
|
-
}
|
17145
|
-
}
|
17146
|
-
);
|
17147
|
-
const environment = colors$1.dim(`(${this.name})`);
|
17148
|
-
const colorIndex = [...this.name].reduce((acc, c) => acc + c.charCodeAt(0), 0) % environmentColors.length;
|
17149
|
-
const infoColor = environmentColors[colorIndex || 0];
|
17150
|
-
this.logger = {
|
17151
|
-
get hasWarned() {
|
17152
|
-
return topLevelConfig.logger.hasWarned;
|
17153
|
-
},
|
17154
|
-
info(msg, opts) {
|
17155
|
-
return topLevelConfig.logger.info(msg, {
|
17156
|
-
...opts,
|
17157
|
-
environment: infoColor(environment)
|
17158
|
-
});
|
17159
|
-
},
|
17160
|
-
warn(msg, opts) {
|
17161
|
-
return topLevelConfig.logger.warn(msg, {
|
17162
|
-
...opts,
|
17163
|
-
environment: colors$1.yellow(environment)
|
17164
|
-
});
|
17165
|
-
},
|
17166
|
-
warnOnce(msg, opts) {
|
17167
|
-
return topLevelConfig.logger.warnOnce(msg, {
|
17168
|
-
...opts,
|
17169
|
-
environment: colors$1.yellow(environment)
|
17170
|
-
});
|
17171
|
-
},
|
17172
|
-
error(msg, opts) {
|
17173
|
-
return topLevelConfig.logger.error(msg, {
|
17174
|
-
...opts,
|
17175
|
-
environment: colors$1.red(environment)
|
17176
|
-
});
|
17177
|
-
},
|
17178
|
-
clearScreen(type) {
|
17179
|
-
return topLevelConfig.logger.clearScreen(type);
|
17180
|
-
},
|
17181
|
-
hasErrorLogged(error) {
|
17182
|
-
return topLevelConfig.logger.hasErrorLogged(error);
|
17183
|
-
}
|
17184
|
-
};
|
17185
|
-
}
|
17186
|
-
}
|
17187
|
-
class BaseEnvironment extends PartialEnvironment {
|
17188
|
-
get plugins() {
|
17189
|
-
if (!this._plugins)
|
17190
|
-
throw new Error(
|
17191
|
-
`${this.name} environment.plugins called before initialized`
|
17192
|
-
);
|
17193
|
-
return this._plugins;
|
16498
|
+
return this._plugins;
|
17194
16499
|
}
|
17195
16500
|
/**
|
17196
16501
|
* @internal
|
@@ -18172,7 +17477,7 @@ function devToScanEnvironment(environment) {
|
|
18172
17477
|
}
|
18173
17478
|
};
|
18174
17479
|
}
|
18175
|
-
const debug$
|
17480
|
+
const debug$g = createDebugger("vite:deps");
|
18176
17481
|
const htmlTypesRE = /\.(html|vue|svelte|astro|imba)$/;
|
18177
17482
|
const importsRE = /(?<!\/\/.*)(?<=^|;|\*\/)\s*import(?!\s+type)(?:[\w*{}\n\r\t, ]+from)?\s*("[^"]+"|'[^']+')\s*(?=$|;|\/\/|\/\*)/gm;
|
18178
17483
|
function scanImports(environment) {
|
@@ -18197,7 +17502,7 @@ function scanImports(environment) {
|
|
18197
17502
|
return;
|
18198
17503
|
}
|
18199
17504
|
if (scanContext.cancelled) return;
|
18200
|
-
debug$
|
17505
|
+
debug$g?.(
|
18201
17506
|
`Crawling dependencies using entries: ${entries.map((entry) => `
|
18202
17507
|
${colors$1.dim(entry)}`).join("")}`
|
18203
17508
|
);
|
@@ -18249,11 +17554,11 @@ function scanImports(environment) {
|
|
18249
17554
|
}
|
18250
17555
|
throw e;
|
18251
17556
|
}).finally(() => {
|
18252
|
-
if (debug$
|
17557
|
+
if (debug$g) {
|
18253
17558
|
const duration = (performance$1.now() - start).toFixed(2);
|
18254
17559
|
const depsStr = Object.keys(orderedDependencies(deps)).sort().map((id) => `
|
18255
17560
|
${colors$1.cyan(id)} -> ${colors$1.dim(deps[id])}`).join("") || colors$1.dim("no dependencies found");
|
18256
|
-
debug$
|
17561
|
+
debug$g(`Scan completed in ${duration}ms: ${depsStr}`);
|
18257
17562
|
}
|
18258
17563
|
});
|
18259
17564
|
return {
|
@@ -18767,14 +18072,14 @@ function nestedResolveBasedir(id, basedir, preserveSymlinks = false) {
|
|
18767
18072
|
return basedir;
|
18768
18073
|
}
|
18769
18074
|
|
18770
|
-
const debug$
|
18075
|
+
const debug$f = createDebugger("vite:deps");
|
18771
18076
|
const jsExtensionRE = /\.js$/i;
|
18772
18077
|
const jsMapExtensionRE = /\.js\.map$/i;
|
18773
18078
|
function isDepOptimizationDisabled(optimizeDeps2) {
|
18774
18079
|
return optimizeDeps2.disabled === true || optimizeDeps2.disabled === "dev" || !!optimizeDeps2.noDiscovery && !optimizeDeps2.include?.length;
|
18775
18080
|
}
|
18776
18081
|
async function optimizeDeps(config, force = config.optimizeDeps.force, asCommand = false) {
|
18777
|
-
const log = asCommand ? config.logger.info : debug$
|
18082
|
+
const log = asCommand ? config.logger.info : debug$f;
|
18778
18083
|
config.logger.warn(
|
18779
18084
|
colors$1.yellow(
|
18780
18085
|
"manually calling optimizeDeps is deprecated. This is done automatically and does not need to be called manually."
|
@@ -18836,7 +18141,7 @@ function addOptimizedDepInfo(metadata, type, depInfo) {
|
|
18836
18141
|
}
|
18837
18142
|
let firstLoadCachedDepOptimizationMetadata = true;
|
18838
18143
|
async function loadCachedDepOptimizationMetadata(environment, force = environment.config.optimizeDeps.force ?? false, asCommand = false) {
|
18839
|
-
const log = asCommand ? environment.logger.info : debug$
|
18144
|
+
const log = asCommand ? environment.logger.info : debug$f;
|
18840
18145
|
if (firstLoadCachedDepOptimizationMetadata) {
|
18841
18146
|
firstLoadCachedDepOptimizationMetadata = false;
|
18842
18147
|
setTimeout(
|
@@ -18882,7 +18187,7 @@ async function loadCachedDepOptimizationMetadata(environment, force = environmen
|
|
18882
18187
|
timestamp: true
|
18883
18188
|
});
|
18884
18189
|
}
|
18885
|
-
debug$
|
18190
|
+
debug$f?.(
|
18886
18191
|
`(${environment.name}) ${colors$1.green(`removing old cache dir ${depsCacheDir}`)}`
|
18887
18192
|
);
|
18888
18193
|
await fsp.rm(depsCacheDir, { recursive: true, force: true });
|
@@ -18938,7 +18243,7 @@ function runOptimizeDeps(environment, depsInfo) {
|
|
18938
18243
|
const depsCacheDir = getDepsCacheDir(environment);
|
18939
18244
|
const processingCacheDir = getProcessingDepsCacheDir(environment);
|
18940
18245
|
fs__default.mkdirSync(processingCacheDir, { recursive: true });
|
18941
|
-
debug$
|
18246
|
+
debug$f?.(colors$1.green(`creating package.json in ${processingCacheDir}`));
|
18942
18247
|
fs__default.writeFileSync(
|
18943
18248
|
path$d.resolve(processingCacheDir, "package.json"),
|
18944
18249
|
`{
|
@@ -18957,7 +18262,7 @@ function runOptimizeDeps(environment, depsInfo) {
|
|
18957
18262
|
const cleanUp = () => {
|
18958
18263
|
if (!cleaned && !committed) {
|
18959
18264
|
cleaned = true;
|
18960
|
-
debug$
|
18265
|
+
debug$f?.(colors$1.green(`removing cache dir ${processingCacheDir}`));
|
18961
18266
|
try {
|
18962
18267
|
fs__default.rmSync(processingCacheDir, { recursive: true, force: true });
|
18963
18268
|
} catch {
|
@@ -18975,7 +18280,7 @@ function runOptimizeDeps(environment, depsInfo) {
|
|
18975
18280
|
}
|
18976
18281
|
committed = true;
|
18977
18282
|
const dataPath = path$d.join(processingCacheDir, METADATA_FILENAME);
|
18978
|
-
debug$
|
18283
|
+
debug$f?.(
|
18979
18284
|
colors$1.green(`creating ${METADATA_FILENAME} in ${processingCacheDir}`)
|
18980
18285
|
);
|
18981
18286
|
fs__default.writeFileSync(
|
@@ -18986,25 +18291,25 @@ function runOptimizeDeps(environment, depsInfo) {
|
|
18986
18291
|
const depsCacheDirPresent = fs__default.existsSync(depsCacheDir);
|
18987
18292
|
if (isWindows$3) {
|
18988
18293
|
if (depsCacheDirPresent) {
|
18989
|
-
debug$
|
18294
|
+
debug$f?.(colors$1.green(`renaming ${depsCacheDir} to ${temporaryPath}`));
|
18990
18295
|
await safeRename(depsCacheDir, temporaryPath);
|
18991
18296
|
}
|
18992
|
-
debug$
|
18297
|
+
debug$f?.(
|
18993
18298
|
colors$1.green(`renaming ${processingCacheDir} to ${depsCacheDir}`)
|
18994
18299
|
);
|
18995
18300
|
await safeRename(processingCacheDir, depsCacheDir);
|
18996
18301
|
} else {
|
18997
18302
|
if (depsCacheDirPresent) {
|
18998
|
-
debug$
|
18303
|
+
debug$f?.(colors$1.green(`renaming ${depsCacheDir} to ${temporaryPath}`));
|
18999
18304
|
fs__default.renameSync(depsCacheDir, temporaryPath);
|
19000
18305
|
}
|
19001
|
-
debug$
|
18306
|
+
debug$f?.(
|
19002
18307
|
colors$1.green(`renaming ${processingCacheDir} to ${depsCacheDir}`)
|
19003
18308
|
);
|
19004
18309
|
fs__default.renameSync(processingCacheDir, depsCacheDir);
|
19005
18310
|
}
|
19006
18311
|
if (depsCacheDirPresent) {
|
19007
|
-
debug$
|
18312
|
+
debug$f?.(colors$1.green(`removing cache temp dir ${temporaryPath}`));
|
19008
18313
|
fsp.rm(temporaryPath, { recursive: true, force: true });
|
19009
18314
|
}
|
19010
18315
|
}
|
@@ -19103,628 +18408,1325 @@ function runOptimizeDeps(environment, depsInfo) {
|
|
19103
18408
|
}
|
19104
18409
|
}
|
19105
18410
|
}
|
19106
|
-
debug$
|
19107
|
-
`Dependencies bundled in ${(performance$1.now() - start).toFixed(2)}ms`
|
19108
|
-
);
|
19109
|
-
return successfulResult;
|
19110
|
-
}).catch((e) => {
|
19111
|
-
if (e.errors && e.message.includes("The build was canceled")) {
|
19112
|
-
return cancelledResult;
|
18411
|
+
debug$f?.(
|
18412
|
+
`Dependencies bundled in ${(performance$1.now() - start).toFixed(2)}ms`
|
18413
|
+
);
|
18414
|
+
return successfulResult;
|
18415
|
+
}).catch((e) => {
|
18416
|
+
if (e.errors && e.message.includes("The build was canceled")) {
|
18417
|
+
return cancelledResult;
|
18418
|
+
}
|
18419
|
+
throw e;
|
18420
|
+
}).finally(() => {
|
18421
|
+
return disposeContext();
|
18422
|
+
});
|
18423
|
+
});
|
18424
|
+
runResult.catch(() => {
|
18425
|
+
cleanUp();
|
18426
|
+
});
|
18427
|
+
return {
|
18428
|
+
async cancel() {
|
18429
|
+
optimizerContext.cancelled = true;
|
18430
|
+
const { context } = await preparedRun;
|
18431
|
+
await context?.cancel();
|
18432
|
+
cleanUp();
|
18433
|
+
},
|
18434
|
+
result: runResult
|
18435
|
+
};
|
18436
|
+
}
|
18437
|
+
async function prepareEsbuildOptimizerRun(environment, depsInfo, processingCacheDir, optimizerContext) {
|
18438
|
+
const flatIdDeps = {};
|
18439
|
+
const idToExports = {};
|
18440
|
+
const { optimizeDeps: optimizeDeps2 } = environment.config;
|
18441
|
+
const { plugins: pluginsFromConfig = [], ...esbuildOptions } = optimizeDeps2.esbuildOptions ?? {};
|
18442
|
+
await Promise.all(
|
18443
|
+
Object.keys(depsInfo).map(async (id) => {
|
18444
|
+
const src = depsInfo[id].src;
|
18445
|
+
const exportsData = await (depsInfo[id].exportsData ?? extractExportsData(environment, src));
|
18446
|
+
if (exportsData.jsxLoader && !esbuildOptions.loader?.[".js"]) {
|
18447
|
+
esbuildOptions.loader = {
|
18448
|
+
".js": "jsx",
|
18449
|
+
...esbuildOptions.loader
|
18450
|
+
};
|
18451
|
+
}
|
18452
|
+
const flatId = flattenId(id);
|
18453
|
+
flatIdDeps[flatId] = src;
|
18454
|
+
idToExports[id] = exportsData;
|
18455
|
+
})
|
18456
|
+
);
|
18457
|
+
if (optimizerContext.cancelled) return { context: void 0, idToExports };
|
18458
|
+
const define = {
|
18459
|
+
"process.env.NODE_ENV": environment.config.keepProcessEnv ? (
|
18460
|
+
// define process.env.NODE_ENV even for keepProcessEnv === true
|
18461
|
+
// as esbuild will replace it automatically when `platform` is `'browser'`
|
18462
|
+
"process.env.NODE_ENV"
|
18463
|
+
) : JSON.stringify(process.env.NODE_ENV || environment.config.mode)
|
18464
|
+
};
|
18465
|
+
const platform = optimizeDeps2.esbuildOptions?.platform ?? // We generally don't want to use platform 'neutral', as esbuild has custom handling
|
18466
|
+
// when the platform is 'node' or 'browser' that can't be emulated by using mainFields
|
18467
|
+
// and conditions
|
18468
|
+
(environment.config.consumer === "client" || environment.config.ssr.target === "webworker" ? "browser" : "node");
|
18469
|
+
const external = [...optimizeDeps2.exclude ?? []];
|
18470
|
+
const plugins = [...pluginsFromConfig];
|
18471
|
+
if (external.length) {
|
18472
|
+
plugins.push(esbuildCjsExternalPlugin(external, platform));
|
18473
|
+
}
|
18474
|
+
plugins.push(esbuildDepPlugin(environment, flatIdDeps, external));
|
18475
|
+
const context = await esbuild.context({
|
18476
|
+
absWorkingDir: process.cwd(),
|
18477
|
+
entryPoints: Object.keys(flatIdDeps),
|
18478
|
+
bundle: true,
|
18479
|
+
platform,
|
18480
|
+
define,
|
18481
|
+
format: "esm",
|
18482
|
+
// See https://github.com/evanw/esbuild/issues/1921#issuecomment-1152991694
|
18483
|
+
banner: platform === "node" ? {
|
18484
|
+
js: `import { createRequire } from 'module';const require = createRequire(import.meta.url);`
|
18485
|
+
} : void 0,
|
18486
|
+
target: ESBUILD_MODULES_TARGET,
|
18487
|
+
external,
|
18488
|
+
logLevel: "error",
|
18489
|
+
splitting: true,
|
18490
|
+
sourcemap: true,
|
18491
|
+
outdir: processingCacheDir,
|
18492
|
+
ignoreAnnotations: true,
|
18493
|
+
metafile: true,
|
18494
|
+
plugins,
|
18495
|
+
charset: "utf8",
|
18496
|
+
...esbuildOptions,
|
18497
|
+
supported: {
|
18498
|
+
...defaultEsbuildSupported,
|
18499
|
+
...esbuildOptions.supported
|
18500
|
+
}
|
18501
|
+
});
|
18502
|
+
return { context, idToExports };
|
18503
|
+
}
|
18504
|
+
async function addManuallyIncludedOptimizeDeps(environment, deps) {
|
18505
|
+
const { logger } = environment;
|
18506
|
+
const { optimizeDeps: optimizeDeps2 } = environment.config;
|
18507
|
+
const optimizeDepsInclude = optimizeDeps2.include ?? [];
|
18508
|
+
if (optimizeDepsInclude.length) {
|
18509
|
+
const unableToOptimize = (id, msg) => {
|
18510
|
+
if (optimizeDepsInclude.includes(id)) {
|
18511
|
+
logger.warn(
|
18512
|
+
`${msg}: ${colors$1.cyan(id)}, present in ${environment.name} 'optimizeDeps.include'`
|
18513
|
+
);
|
18514
|
+
}
|
18515
|
+
};
|
18516
|
+
const includes = [...optimizeDepsInclude];
|
18517
|
+
for (let i = 0; i < includes.length; i++) {
|
18518
|
+
const id = includes[i];
|
18519
|
+
if (isDynamicPattern(id)) {
|
18520
|
+
const globIds = expandGlobIds(id, environment.getTopLevelConfig());
|
18521
|
+
includes.splice(i, 1, ...globIds);
|
18522
|
+
i += globIds.length - 1;
|
18523
|
+
}
|
18524
|
+
}
|
18525
|
+
const resolve = createOptimizeDepsIncludeResolver(environment);
|
18526
|
+
for (const id of includes) {
|
18527
|
+
const normalizedId = normalizeId(id);
|
18528
|
+
if (!deps[normalizedId]) {
|
18529
|
+
const entry = await resolve(id);
|
18530
|
+
if (entry) {
|
18531
|
+
if (isOptimizable(entry, optimizeDeps2)) {
|
18532
|
+
deps[normalizedId] = entry;
|
18533
|
+
} else {
|
18534
|
+
unableToOptimize(id, "Cannot optimize dependency");
|
18535
|
+
}
|
18536
|
+
} else {
|
18537
|
+
unableToOptimize(id, "Failed to resolve dependency");
|
18538
|
+
}
|
18539
|
+
}
|
18540
|
+
}
|
18541
|
+
}
|
18542
|
+
}
|
18543
|
+
function depsFromOptimizedDepInfo(depsInfo) {
|
18544
|
+
const obj = {};
|
18545
|
+
for (const key in depsInfo) {
|
18546
|
+
obj[key] = depsInfo[key].src;
|
18547
|
+
}
|
18548
|
+
return obj;
|
18549
|
+
}
|
18550
|
+
function getOptimizedDepPath(environment, id) {
|
18551
|
+
return normalizePath$3(
|
18552
|
+
path$d.resolve(getDepsCacheDir(environment), flattenId(id) + ".js")
|
18553
|
+
);
|
18554
|
+
}
|
18555
|
+
function getDepsCacheSuffix(environment) {
|
18556
|
+
return environment.name === "client" ? "" : `_${environment.name}`;
|
18557
|
+
}
|
18558
|
+
function getDepsCacheDir(environment) {
|
18559
|
+
return getDepsCacheDirPrefix(environment) + getDepsCacheSuffix(environment);
|
18560
|
+
}
|
18561
|
+
function getProcessingDepsCacheDir(environment) {
|
18562
|
+
return getDepsCacheDirPrefix(environment) + getDepsCacheSuffix(environment) + getTempSuffix();
|
18563
|
+
}
|
18564
|
+
function getTempSuffix() {
|
18565
|
+
return "_temp_" + getHash(
|
18566
|
+
`${process.pid}:${Date.now().toString()}:${Math.random().toString(16).slice(2)}`
|
18567
|
+
);
|
18568
|
+
}
|
18569
|
+
function getDepsCacheDirPrefix(environment) {
|
18570
|
+
return normalizePath$3(path$d.resolve(environment.config.cacheDir, "deps"));
|
18571
|
+
}
|
18572
|
+
function createIsOptimizedDepFile(environment) {
|
18573
|
+
const depsCacheDirPrefix = getDepsCacheDirPrefix(environment);
|
18574
|
+
return (id) => id.startsWith(depsCacheDirPrefix);
|
18575
|
+
}
|
18576
|
+
function createIsOptimizedDepUrl(environment) {
|
18577
|
+
const { root } = environment.config;
|
18578
|
+
const depsCacheDir = getDepsCacheDirPrefix(environment);
|
18579
|
+
const depsCacheDirRelative = normalizePath$3(path$d.relative(root, depsCacheDir));
|
18580
|
+
const depsCacheDirPrefix = depsCacheDirRelative.startsWith("../") ? (
|
18581
|
+
// if the cache directory is outside root, the url prefix would be something
|
18582
|
+
// like '/@fs/absolute/path/to/node_modules/.vite'
|
18583
|
+
`/@fs/${removeLeadingSlash(normalizePath$3(depsCacheDir))}`
|
18584
|
+
) : (
|
18585
|
+
// if the cache directory is inside root, the url prefix would be something
|
18586
|
+
// like '/node_modules/.vite'
|
18587
|
+
`/${depsCacheDirRelative}`
|
18588
|
+
);
|
18589
|
+
return function isOptimizedDepUrl(url) {
|
18590
|
+
return url.startsWith(depsCacheDirPrefix);
|
18591
|
+
};
|
18592
|
+
}
|
18593
|
+
function parseDepsOptimizerMetadata(jsonMetadata, depsCacheDir) {
|
18594
|
+
const { hash, lockfileHash, configHash, browserHash, optimized, chunks } = JSON.parse(jsonMetadata, (key, value) => {
|
18595
|
+
if (key === "file" || key === "src") {
|
18596
|
+
return normalizePath$3(path$d.resolve(depsCacheDir, value));
|
18597
|
+
}
|
18598
|
+
return value;
|
18599
|
+
});
|
18600
|
+
if (!chunks || Object.values(optimized).some((depInfo) => !depInfo.fileHash)) {
|
18601
|
+
return;
|
18602
|
+
}
|
18603
|
+
const metadata = {
|
18604
|
+
hash,
|
18605
|
+
lockfileHash,
|
18606
|
+
configHash,
|
18607
|
+
browserHash,
|
18608
|
+
optimized: {},
|
18609
|
+
discovered: {},
|
18610
|
+
chunks: {},
|
18611
|
+
depInfoList: []
|
18612
|
+
};
|
18613
|
+
for (const id of Object.keys(optimized)) {
|
18614
|
+
addOptimizedDepInfo(metadata, "optimized", {
|
18615
|
+
...optimized[id],
|
18616
|
+
id,
|
18617
|
+
browserHash
|
18618
|
+
});
|
18619
|
+
}
|
18620
|
+
for (const id of Object.keys(chunks)) {
|
18621
|
+
addOptimizedDepInfo(metadata, "chunks", {
|
18622
|
+
...chunks[id],
|
18623
|
+
id,
|
18624
|
+
browserHash,
|
18625
|
+
needsInterop: false
|
18626
|
+
});
|
18627
|
+
}
|
18628
|
+
return metadata;
|
18629
|
+
}
|
18630
|
+
function stringifyDepsOptimizerMetadata(metadata, depsCacheDir) {
|
18631
|
+
const { hash, configHash, lockfileHash, browserHash, optimized, chunks } = metadata;
|
18632
|
+
return JSON.stringify(
|
18633
|
+
{
|
18634
|
+
hash,
|
18635
|
+
configHash,
|
18636
|
+
lockfileHash,
|
18637
|
+
browserHash,
|
18638
|
+
optimized: Object.fromEntries(
|
18639
|
+
Object.values(optimized).map(
|
18640
|
+
({ id, src, file, fileHash, needsInterop: needsInterop2 }) => [
|
18641
|
+
id,
|
18642
|
+
{
|
18643
|
+
src,
|
18644
|
+
file,
|
18645
|
+
fileHash,
|
18646
|
+
needsInterop: needsInterop2
|
18647
|
+
}
|
18648
|
+
]
|
18649
|
+
)
|
18650
|
+
),
|
18651
|
+
chunks: Object.fromEntries(
|
18652
|
+
Object.values(chunks).map(({ id, file }) => [id, { file }])
|
18653
|
+
)
|
18654
|
+
},
|
18655
|
+
(key, value) => {
|
18656
|
+
if (key === "file" || key === "src") {
|
18657
|
+
return normalizePath$3(path$d.relative(depsCacheDir, value));
|
18658
|
+
}
|
18659
|
+
return value;
|
18660
|
+
},
|
18661
|
+
2
|
18662
|
+
);
|
18663
|
+
}
|
18664
|
+
function esbuildOutputFromId(outputs, id, cacheDirOutputPath) {
|
18665
|
+
const cwd = process.cwd();
|
18666
|
+
const flatId = flattenId(id) + ".js";
|
18667
|
+
const normalizedOutputPath = normalizePath$3(
|
18668
|
+
path$d.relative(cwd, path$d.join(cacheDirOutputPath, flatId))
|
18669
|
+
);
|
18670
|
+
const output = outputs[normalizedOutputPath];
|
18671
|
+
if (output) {
|
18672
|
+
return output;
|
18673
|
+
}
|
18674
|
+
for (const [key, value] of Object.entries(outputs)) {
|
18675
|
+
if (normalizePath$3(path$d.relative(cwd, key)) === normalizedOutputPath) {
|
18676
|
+
return value;
|
18677
|
+
}
|
18678
|
+
}
|
18679
|
+
}
|
18680
|
+
async function extractExportsData(environment, filePath) {
|
18681
|
+
await init;
|
18682
|
+
const { optimizeDeps: optimizeDeps2 } = environment.config;
|
18683
|
+
const esbuildOptions = optimizeDeps2.esbuildOptions ?? {};
|
18684
|
+
if (optimizeDeps2.extensions?.some((ext) => filePath.endsWith(ext))) {
|
18685
|
+
const result = await build$b({
|
18686
|
+
...esbuildOptions,
|
18687
|
+
entryPoints: [filePath],
|
18688
|
+
write: false,
|
18689
|
+
format: "esm"
|
18690
|
+
});
|
18691
|
+
const [, exports2, , hasModuleSyntax2] = parse$e(result.outputFiles[0].text);
|
18692
|
+
return {
|
18693
|
+
hasModuleSyntax: hasModuleSyntax2,
|
18694
|
+
exports: exports2.map((e) => e.n)
|
18695
|
+
};
|
18696
|
+
}
|
18697
|
+
let parseResult;
|
18698
|
+
let usedJsxLoader = false;
|
18699
|
+
const entryContent = await fsp.readFile(filePath, "utf-8");
|
18700
|
+
try {
|
18701
|
+
parseResult = parse$e(entryContent);
|
18702
|
+
} catch {
|
18703
|
+
const loader = esbuildOptions.loader?.[path$d.extname(filePath)] || "jsx";
|
18704
|
+
debug$f?.(
|
18705
|
+
`Unable to parse: ${filePath}.
|
18706
|
+
Trying again with a ${loader} transform.`
|
18707
|
+
);
|
18708
|
+
const transformed = await transformWithEsbuild(
|
18709
|
+
entryContent,
|
18710
|
+
filePath,
|
18711
|
+
{ loader },
|
18712
|
+
void 0,
|
18713
|
+
environment.config
|
18714
|
+
);
|
18715
|
+
parseResult = parse$e(transformed.code);
|
18716
|
+
usedJsxLoader = true;
|
18717
|
+
}
|
18718
|
+
const [, exports, , hasModuleSyntax] = parseResult;
|
18719
|
+
const exportsData = {
|
18720
|
+
hasModuleSyntax,
|
18721
|
+
exports: exports.map((e) => e.n),
|
18722
|
+
jsxLoader: usedJsxLoader
|
18723
|
+
};
|
18724
|
+
return exportsData;
|
18725
|
+
}
|
18726
|
+
function needsInterop(environment, id, exportsData, output) {
|
18727
|
+
if (environment.config.optimizeDeps.needsInterop?.includes(id)) {
|
18728
|
+
return true;
|
18729
|
+
}
|
18730
|
+
const { hasModuleSyntax, exports } = exportsData;
|
18731
|
+
if (!hasModuleSyntax) {
|
18732
|
+
return true;
|
18733
|
+
}
|
18734
|
+
if (output) {
|
18735
|
+
const generatedExports = output.exports;
|
18736
|
+
if (isSingleDefaultExport(generatedExports) && !isSingleDefaultExport(exports)) {
|
18737
|
+
return true;
|
18738
|
+
}
|
18739
|
+
}
|
18740
|
+
return false;
|
18741
|
+
}
|
18742
|
+
function isSingleDefaultExport(exports) {
|
18743
|
+
return exports.length === 1 && exports[0] === "default";
|
18744
|
+
}
|
18745
|
+
const lockfileFormats = [
|
18746
|
+
{
|
18747
|
+
path: "node_modules/.package-lock.json",
|
18748
|
+
checkPatchesDir: "patches",
|
18749
|
+
manager: "npm"
|
18750
|
+
},
|
18751
|
+
{
|
18752
|
+
// Yarn non-PnP
|
18753
|
+
path: "node_modules/.yarn-state.yml",
|
18754
|
+
checkPatchesDir: false,
|
18755
|
+
manager: "yarn"
|
18756
|
+
},
|
18757
|
+
{
|
18758
|
+
// Yarn v3+ PnP
|
18759
|
+
path: ".pnp.cjs",
|
18760
|
+
checkPatchesDir: ".yarn/patches",
|
18761
|
+
manager: "yarn"
|
18762
|
+
},
|
18763
|
+
{
|
18764
|
+
// Yarn v2 PnP
|
18765
|
+
path: ".pnp.js",
|
18766
|
+
checkPatchesDir: ".yarn/patches",
|
18767
|
+
manager: "yarn"
|
18768
|
+
},
|
18769
|
+
{
|
18770
|
+
// yarn 1
|
18771
|
+
path: "node_modules/.yarn-integrity",
|
18772
|
+
checkPatchesDir: "patches",
|
18773
|
+
manager: "yarn"
|
18774
|
+
},
|
18775
|
+
{
|
18776
|
+
path: "node_modules/.pnpm/lock.yaml",
|
18777
|
+
// Included in lockfile
|
18778
|
+
checkPatchesDir: false,
|
18779
|
+
manager: "pnpm"
|
18780
|
+
},
|
18781
|
+
{
|
18782
|
+
path: "bun.lock",
|
18783
|
+
checkPatchesDir: "patches",
|
18784
|
+
manager: "bun"
|
18785
|
+
},
|
18786
|
+
{
|
18787
|
+
path: "bun.lockb",
|
18788
|
+
checkPatchesDir: "patches",
|
18789
|
+
manager: "bun"
|
18790
|
+
}
|
18791
|
+
].sort((_, { manager }) => {
|
18792
|
+
return process.env.npm_config_user_agent?.startsWith(manager) ? 1 : -1;
|
18793
|
+
});
|
18794
|
+
const lockfilePaths = lockfileFormats.map((l) => l.path);
|
18795
|
+
function getConfigHash(environment) {
|
18796
|
+
const { config } = environment;
|
18797
|
+
const { optimizeDeps: optimizeDeps2 } = config;
|
18798
|
+
const content = JSON.stringify(
|
18799
|
+
{
|
18800
|
+
define: !config.keepProcessEnv ? process.env.NODE_ENV || config.mode : null,
|
18801
|
+
root: config.root,
|
18802
|
+
resolve: config.resolve,
|
18803
|
+
assetsInclude: config.assetsInclude,
|
18804
|
+
plugins: config.plugins.map((p) => p.name),
|
18805
|
+
optimizeDeps: {
|
18806
|
+
include: optimizeDeps2.include ? unique(optimizeDeps2.include).sort() : void 0,
|
18807
|
+
exclude: optimizeDeps2.exclude ? unique(optimizeDeps2.exclude).sort() : void 0,
|
18808
|
+
esbuildOptions: {
|
18809
|
+
...optimizeDeps2.esbuildOptions,
|
18810
|
+
plugins: optimizeDeps2.esbuildOptions?.plugins?.map((p) => p.name)
|
18811
|
+
}
|
18812
|
+
}
|
18813
|
+
},
|
18814
|
+
(_, value) => {
|
18815
|
+
if (typeof value === "function" || value instanceof RegExp) {
|
18816
|
+
return value.toString();
|
18817
|
+
}
|
18818
|
+
return value;
|
18819
|
+
}
|
18820
|
+
);
|
18821
|
+
return getHash(content);
|
18822
|
+
}
|
18823
|
+
function getLockfileHash(environment) {
|
18824
|
+
const lockfilePath = lookupFile(environment.config.root, lockfilePaths);
|
18825
|
+
let content = lockfilePath ? fs__default.readFileSync(lockfilePath, "utf-8") : "";
|
18826
|
+
if (lockfilePath) {
|
18827
|
+
const normalizedLockfilePath = lockfilePath.replaceAll("\\", "/");
|
18828
|
+
const lockfileFormat = lockfileFormats.find(
|
18829
|
+
(f) => normalizedLockfilePath.endsWith(f.path)
|
18830
|
+
);
|
18831
|
+
if (lockfileFormat.checkPatchesDir) {
|
18832
|
+
const baseDir = lockfilePath.slice(0, -lockfileFormat.path.length);
|
18833
|
+
const fullPath = path$d.join(
|
18834
|
+
baseDir,
|
18835
|
+
lockfileFormat.checkPatchesDir
|
18836
|
+
);
|
18837
|
+
const stat = tryStatSync(fullPath);
|
18838
|
+
if (stat?.isDirectory()) {
|
18839
|
+
content += stat.mtimeMs.toString();
|
18840
|
+
}
|
18841
|
+
}
|
18842
|
+
}
|
18843
|
+
return getHash(content);
|
18844
|
+
}
|
18845
|
+
function getDepHash(environment) {
|
18846
|
+
const lockfileHash = getLockfileHash(environment);
|
18847
|
+
const configHash = getConfigHash(environment);
|
18848
|
+
const hash = getHash(lockfileHash + configHash);
|
18849
|
+
return {
|
18850
|
+
hash,
|
18851
|
+
lockfileHash,
|
18852
|
+
configHash
|
18853
|
+
};
|
18854
|
+
}
|
18855
|
+
function getOptimizedBrowserHash(hash, deps, timestamp = "") {
|
18856
|
+
return getHash(hash + JSON.stringify(deps) + timestamp);
|
18857
|
+
}
|
18858
|
+
function optimizedDepInfoFromId(metadata, id) {
|
18859
|
+
return metadata.optimized[id] || metadata.discovered[id] || metadata.chunks[id];
|
18860
|
+
}
|
18861
|
+
function optimizedDepInfoFromFile(metadata, file) {
|
18862
|
+
return metadata.depInfoList.find((depInfo) => depInfo.file === file);
|
18863
|
+
}
|
18864
|
+
function findOptimizedDepInfoInRecord(dependenciesInfo, callbackFn) {
|
18865
|
+
for (const o of Object.keys(dependenciesInfo)) {
|
18866
|
+
const info = dependenciesInfo[o];
|
18867
|
+
if (callbackFn(info, o)) {
|
18868
|
+
return info;
|
18869
|
+
}
|
18870
|
+
}
|
18871
|
+
}
|
18872
|
+
async function optimizedDepNeedsInterop(environment, metadata, file) {
|
18873
|
+
const depInfo = optimizedDepInfoFromFile(metadata, file);
|
18874
|
+
if (depInfo?.src && depInfo.needsInterop === void 0) {
|
18875
|
+
depInfo.exportsData ??= extractExportsData(environment, depInfo.src);
|
18876
|
+
depInfo.needsInterop = needsInterop(
|
18877
|
+
environment,
|
18878
|
+
depInfo.id,
|
18879
|
+
await depInfo.exportsData
|
18880
|
+
);
|
18881
|
+
}
|
18882
|
+
return depInfo?.needsInterop;
|
18883
|
+
}
|
18884
|
+
const MAX_TEMP_DIR_AGE_MS = 24 * 60 * 60 * 1e3;
|
18885
|
+
async function cleanupDepsCacheStaleDirs(config) {
|
18886
|
+
try {
|
18887
|
+
const cacheDir = path$d.resolve(config.cacheDir);
|
18888
|
+
if (fs__default.existsSync(cacheDir)) {
|
18889
|
+
const dirents = await fsp.readdir(cacheDir, { withFileTypes: true });
|
18890
|
+
for (const dirent of dirents) {
|
18891
|
+
if (dirent.isDirectory() && dirent.name.includes("_temp_")) {
|
18892
|
+
const tempDirPath = path$d.resolve(config.cacheDir, dirent.name);
|
18893
|
+
const stats = await fsp.stat(tempDirPath).catch(() => null);
|
18894
|
+
if (stats?.mtime && Date.now() - stats.mtime.getTime() > MAX_TEMP_DIR_AGE_MS) {
|
18895
|
+
debug$f?.(`removing stale cache temp dir ${tempDirPath}`);
|
18896
|
+
await fsp.rm(tempDirPath, { recursive: true, force: true });
|
18897
|
+
}
|
18898
|
+
}
|
18899
|
+
}
|
18900
|
+
}
|
18901
|
+
} catch (err) {
|
18902
|
+
config.logger.error(err);
|
18903
|
+
}
|
18904
|
+
}
|
18905
|
+
const GRACEFUL_RENAME_TIMEOUT = 5e3;
|
18906
|
+
const safeRename = promisify$4(function gracefulRename(from, to, cb) {
|
18907
|
+
const start = Date.now();
|
18908
|
+
let backoff = 0;
|
18909
|
+
fs__default.rename(from, to, function CB(er) {
|
18910
|
+
if (er && (er.code === "EACCES" || er.code === "EPERM") && Date.now() - start < GRACEFUL_RENAME_TIMEOUT) {
|
18911
|
+
setTimeout(function() {
|
18912
|
+
fs__default.stat(to, function(stater, _st) {
|
18913
|
+
if (stater && stater.code === "ENOENT") fs__default.rename(from, to, CB);
|
18914
|
+
else CB(er);
|
18915
|
+
});
|
18916
|
+
}, backoff);
|
18917
|
+
if (backoff < 100) backoff += 10;
|
18918
|
+
return;
|
18919
|
+
}
|
18920
|
+
cb(er);
|
18921
|
+
});
|
18922
|
+
});
|
18923
|
+
|
18924
|
+
var index$1 = {
|
18925
|
+
__proto__: null,
|
18926
|
+
addManuallyIncludedOptimizeDeps: addManuallyIncludedOptimizeDeps,
|
18927
|
+
addOptimizedDepInfo: addOptimizedDepInfo,
|
18928
|
+
cleanupDepsCacheStaleDirs: cleanupDepsCacheStaleDirs,
|
18929
|
+
createIsOptimizedDepFile: createIsOptimizedDepFile,
|
18930
|
+
createIsOptimizedDepUrl: createIsOptimizedDepUrl,
|
18931
|
+
depsFromOptimizedDepInfo: depsFromOptimizedDepInfo,
|
18932
|
+
depsLogString: depsLogString,
|
18933
|
+
discoverProjectDependencies: discoverProjectDependencies,
|
18934
|
+
extractExportsData: extractExportsData,
|
18935
|
+
getDepsCacheDir: getDepsCacheDir,
|
18936
|
+
getOptimizedDepPath: getOptimizedDepPath,
|
18937
|
+
initDepsOptimizerMetadata: initDepsOptimizerMetadata,
|
18938
|
+
isDepOptimizationDisabled: isDepOptimizationDisabled,
|
18939
|
+
loadCachedDepOptimizationMetadata: loadCachedDepOptimizationMetadata,
|
18940
|
+
optimizeDeps: optimizeDeps,
|
18941
|
+
optimizeExplicitEnvironmentDeps: optimizeExplicitEnvironmentDeps,
|
18942
|
+
optimizedDepInfoFromFile: optimizedDepInfoFromFile,
|
18943
|
+
optimizedDepInfoFromId: optimizedDepInfoFromId,
|
18944
|
+
optimizedDepNeedsInterop: optimizedDepNeedsInterop,
|
18945
|
+
runOptimizeDeps: runOptimizeDeps,
|
18946
|
+
toDiscoveredDependencies: toDiscoveredDependencies
|
18947
|
+
};
|
18948
|
+
|
18949
|
+
const debug$e = createDebugger("vite:external");
|
18950
|
+
const isExternalCache = /* @__PURE__ */ new WeakMap();
|
18951
|
+
function shouldExternalize(environment, id, importer) {
|
18952
|
+
let isExternal = isExternalCache.get(environment);
|
18953
|
+
if (!isExternal) {
|
18954
|
+
isExternal = createIsExternal(environment);
|
18955
|
+
isExternalCache.set(environment, isExternal);
|
18956
|
+
}
|
18957
|
+
return isExternal(id, importer);
|
18958
|
+
}
|
18959
|
+
function createIsConfiguredAsExternal(environment) {
|
18960
|
+
const { config } = environment;
|
18961
|
+
const { root, resolve } = config;
|
18962
|
+
const { external, noExternal } = resolve;
|
18963
|
+
const noExternalFilter = typeof noExternal !== "boolean" && !(Array.isArray(noExternal) && noExternal.length === 0) && createFilter(void 0, noExternal, { resolve: false });
|
18964
|
+
const targetConditions = resolve.externalConditions;
|
18965
|
+
const resolveOptions = {
|
18966
|
+
...resolve,
|
18967
|
+
root,
|
18968
|
+
isProduction: false,
|
18969
|
+
isBuild: true,
|
18970
|
+
conditions: targetConditions
|
18971
|
+
};
|
18972
|
+
const isExternalizable = (id, importer, configuredAsExternal) => {
|
18973
|
+
if (!bareImportRE.test(id) || id.includes("\0")) {
|
18974
|
+
return false;
|
18975
|
+
}
|
18976
|
+
try {
|
18977
|
+
const resolved = tryNodeResolve(
|
18978
|
+
id,
|
18979
|
+
// Skip passing importer in build to avoid externalizing non-hoisted dependencies
|
18980
|
+
// unresolvable from root (which would be unresolvable from output bundles also)
|
18981
|
+
config.command === "build" ? void 0 : importer,
|
18982
|
+
resolveOptions,
|
18983
|
+
void 0,
|
18984
|
+
false
|
18985
|
+
);
|
18986
|
+
if (!resolved) {
|
18987
|
+
return false;
|
18988
|
+
}
|
18989
|
+
if (!configuredAsExternal && !isInNodeModules$1(resolved.id)) {
|
18990
|
+
return false;
|
18991
|
+
}
|
18992
|
+
return canExternalizeFile(resolved.id);
|
18993
|
+
} catch {
|
18994
|
+
debug$e?.(
|
18995
|
+
`Failed to node resolve "${id}". Skipping externalizing it by default.`
|
18996
|
+
);
|
18997
|
+
return false;
|
18998
|
+
}
|
18999
|
+
};
|
19000
|
+
return (id, importer) => {
|
19001
|
+
if (
|
19002
|
+
// If this id is defined as external, force it as external
|
19003
|
+
// Note that individual package entries are allowed in `external`
|
19004
|
+
external !== true && external.includes(id)
|
19005
|
+
) {
|
19006
|
+
return true;
|
19007
|
+
}
|
19008
|
+
const pkgName = getNpmPackageName(id);
|
19009
|
+
if (!pkgName) {
|
19010
|
+
return isExternalizable(id, importer, false);
|
19011
|
+
}
|
19012
|
+
if (
|
19013
|
+
// A package name in ssr.external externalizes every
|
19014
|
+
// externalizable package entry
|
19015
|
+
external !== true && external.includes(pkgName)
|
19016
|
+
) {
|
19017
|
+
return isExternalizable(id, importer, true);
|
19018
|
+
}
|
19019
|
+
if (typeof noExternal === "boolean") {
|
19020
|
+
return !noExternal;
|
19021
|
+
}
|
19022
|
+
if (noExternalFilter && !noExternalFilter(pkgName)) {
|
19023
|
+
return false;
|
19024
|
+
}
|
19025
|
+
return isExternalizable(id, importer, external === true);
|
19026
|
+
};
|
19027
|
+
}
|
19028
|
+
function createIsExternal(environment) {
|
19029
|
+
const processedIds = /* @__PURE__ */ new Map();
|
19030
|
+
const isConfiguredAsExternal = createIsConfiguredAsExternal(environment);
|
19031
|
+
return (id, importer) => {
|
19032
|
+
if (processedIds.has(id)) {
|
19033
|
+
return processedIds.get(id);
|
19034
|
+
}
|
19035
|
+
let isExternal = false;
|
19036
|
+
if (id[0] !== "." && !path$d.isAbsolute(id)) {
|
19037
|
+
isExternal = isBuiltin(environment.config.resolve.builtins, id) || isConfiguredAsExternal(id, importer);
|
19038
|
+
}
|
19039
|
+
processedIds.set(id, isExternal);
|
19040
|
+
return isExternal;
|
19041
|
+
};
|
19042
|
+
}
|
19043
|
+
function canExternalizeFile(filePath) {
|
19044
|
+
const ext = path$d.extname(filePath);
|
19045
|
+
return !ext || ext === ".js" || ext === ".mjs" || ext === ".cjs";
|
19046
|
+
}
|
19047
|
+
|
19048
|
+
const normalizedClientEntry$1 = normalizePath$3(CLIENT_ENTRY);
|
19049
|
+
const normalizedEnvEntry$1 = normalizePath$3(ENV_ENTRY);
|
19050
|
+
const ERR_RESOLVE_PACKAGE_ENTRY_FAIL = "ERR_RESOLVE_PACKAGE_ENTRY_FAIL";
|
19051
|
+
const browserExternalId = "__vite-browser-external";
|
19052
|
+
const optionalPeerDepId = "__vite-optional-peer-dep";
|
19053
|
+
const subpathImportsPrefix = "#";
|
19054
|
+
const startsWithWordCharRE = /^\w/;
|
19055
|
+
const debug$d = createDebugger("vite:resolve-details", {
|
19056
|
+
onlyWhenFocused: true
|
19057
|
+
});
|
19058
|
+
function resolvePlugin(resolveOptions) {
|
19059
|
+
const { root, isProduction, asSrc, preferRelative = false } = resolveOptions;
|
19060
|
+
const rootInRoot = tryStatSync(path$d.join(root, root))?.isDirectory() ?? false;
|
19061
|
+
return {
|
19062
|
+
name: "vite:resolve",
|
19063
|
+
async resolveId(id, importer, resolveOpts) {
|
19064
|
+
if (id[0] === "\0" || id.startsWith("virtual:") || // When injected directly in html/client code
|
19065
|
+
id.startsWith("/virtual:")) {
|
19066
|
+
return;
|
19067
|
+
}
|
19068
|
+
const depsOptimizer = resolveOptions.optimizeDeps && this.environment.mode === "dev" ? this.environment.depsOptimizer : void 0;
|
19069
|
+
if (id.startsWith(browserExternalId)) {
|
19070
|
+
return id;
|
19071
|
+
}
|
19072
|
+
const isRequire = resolveOpts.custom?.["node-resolve"]?.isRequire ?? false;
|
19073
|
+
const currentEnvironmentOptions = this.environment.config;
|
19074
|
+
const options = {
|
19075
|
+
isRequire,
|
19076
|
+
...currentEnvironmentOptions.resolve,
|
19077
|
+
...resolveOptions,
|
19078
|
+
// plugin options + resolve options overrides
|
19079
|
+
scan: resolveOpts.scan ?? resolveOptions.scan
|
19080
|
+
};
|
19081
|
+
const resolvedImports = resolveSubpathImports(id, importer, options);
|
19082
|
+
if (resolvedImports) {
|
19083
|
+
id = resolvedImports;
|
19084
|
+
if (resolveOpts.custom?.["vite:import-glob"]?.isSubImportsPattern) {
|
19085
|
+
return normalizePath$3(path$d.join(root, id));
|
19086
|
+
}
|
19087
|
+
}
|
19088
|
+
let res;
|
19089
|
+
if (asSrc && depsOptimizer?.isOptimizedDepUrl(id)) {
|
19090
|
+
const optimizedPath = id.startsWith(FS_PREFIX) ? fsPathFromId(id) : normalizePath$3(path$d.resolve(root, id.slice(1)));
|
19091
|
+
return optimizedPath;
|
19092
|
+
}
|
19093
|
+
if (asSrc && id.startsWith(FS_PREFIX)) {
|
19094
|
+
res = fsPathFromId(id);
|
19095
|
+
debug$d?.(`[@fs] ${colors$1.cyan(id)} -> ${colors$1.dim(res)}`);
|
19096
|
+
return ensureVersionQuery(res, id, options, depsOptimizer);
|
19097
|
+
}
|
19098
|
+
if (asSrc && id[0] === "/" && (rootInRoot || !id.startsWith(withTrailingSlash(root)))) {
|
19099
|
+
const fsPath = path$d.resolve(root, id.slice(1));
|
19100
|
+
if (res = tryFsResolve(fsPath, options)) {
|
19101
|
+
debug$d?.(`[url] ${colors$1.cyan(id)} -> ${colors$1.dim(res)}`);
|
19102
|
+
return ensureVersionQuery(res, id, options, depsOptimizer);
|
19103
|
+
}
|
19104
|
+
}
|
19105
|
+
if (id[0] === "." || (preferRelative || importer?.endsWith(".html")) && startsWithWordCharRE.test(id)) {
|
19106
|
+
const basedir = importer ? path$d.dirname(importer) : process.cwd();
|
19107
|
+
const fsPath = path$d.resolve(basedir, id);
|
19108
|
+
const normalizedFsPath = normalizePath$3(fsPath);
|
19109
|
+
if (depsOptimizer?.isOptimizedDepFile(normalizedFsPath)) {
|
19110
|
+
if (!options.isBuild && !DEP_VERSION_RE.test(normalizedFsPath)) {
|
19111
|
+
const browserHash = optimizedDepInfoFromFile(
|
19112
|
+
depsOptimizer.metadata,
|
19113
|
+
normalizedFsPath
|
19114
|
+
)?.browserHash;
|
19115
|
+
if (browserHash) {
|
19116
|
+
return injectQuery(normalizedFsPath, `v=${browserHash}`);
|
19117
|
+
}
|
19118
|
+
}
|
19119
|
+
return normalizedFsPath;
|
19120
|
+
}
|
19121
|
+
if (options.mainFields.includes("browser") && (res = tryResolveBrowserMapping(fsPath, importer, options, true))) {
|
19122
|
+
return res;
|
19123
|
+
}
|
19124
|
+
if (res = tryFsResolve(fsPath, options)) {
|
19125
|
+
res = ensureVersionQuery(res, id, options, depsOptimizer);
|
19126
|
+
debug$d?.(`[relative] ${colors$1.cyan(id)} -> ${colors$1.dim(res)}`);
|
19127
|
+
if (!options.idOnly && !options.scan && options.isBuild) {
|
19128
|
+
const resPkg = findNearestPackageData(
|
19129
|
+
path$d.dirname(res),
|
19130
|
+
options.packageCache
|
19131
|
+
);
|
19132
|
+
if (resPkg) {
|
19133
|
+
return {
|
19134
|
+
id: res,
|
19135
|
+
moduleSideEffects: resPkg.hasSideEffects(res)
|
19136
|
+
};
|
19137
|
+
}
|
19138
|
+
}
|
19139
|
+
return res;
|
19140
|
+
}
|
19141
|
+
}
|
19142
|
+
if (id.startsWith("file://")) {
|
19143
|
+
const { file, postfix } = splitFileAndPostfix(id);
|
19144
|
+
id = fileURLToPath$1(file) + postfix;
|
19145
|
+
}
|
19146
|
+
if (isWindows$3 && id[0] === "/") {
|
19147
|
+
const basedir = importer ? path$d.dirname(importer) : process.cwd();
|
19148
|
+
const fsPath = path$d.resolve(basedir, id);
|
19149
|
+
if (res = tryFsResolve(fsPath, options)) {
|
19150
|
+
debug$d?.(`[drive-relative] ${colors$1.cyan(id)} -> ${colors$1.dim(res)}`);
|
19151
|
+
return ensureVersionQuery(res, id, options, depsOptimizer);
|
19152
|
+
}
|
19153
|
+
}
|
19154
|
+
if (isNonDriveRelativeAbsolutePath(id) && (res = tryFsResolve(id, options))) {
|
19155
|
+
debug$d?.(`[fs] ${colors$1.cyan(id)} -> ${colors$1.dim(res)}`);
|
19156
|
+
return ensureVersionQuery(res, id, options, depsOptimizer);
|
19157
|
+
}
|
19158
|
+
if (isExternalUrl(id)) {
|
19159
|
+
return options.idOnly ? id : { id, external: true };
|
19160
|
+
}
|
19161
|
+
if (isDataUrl(id)) {
|
19162
|
+
return null;
|
19163
|
+
}
|
19164
|
+
if (bareImportRE.test(id)) {
|
19165
|
+
const external = options.externalize && options.isBuild && currentEnvironmentOptions.consumer === "server" && shouldExternalize(this.environment, id, importer);
|
19166
|
+
if (!external && asSrc && depsOptimizer && !options.scan && (res = await tryOptimizedResolve(
|
19167
|
+
depsOptimizer,
|
19168
|
+
id,
|
19169
|
+
importer,
|
19170
|
+
options.preserveSymlinks,
|
19171
|
+
options.packageCache
|
19172
|
+
))) {
|
19173
|
+
return res;
|
19174
|
+
}
|
19175
|
+
if (options.mainFields.includes("browser") && (res = tryResolveBrowserMapping(
|
19176
|
+
id,
|
19177
|
+
importer,
|
19178
|
+
options,
|
19179
|
+
false,
|
19180
|
+
external
|
19181
|
+
))) {
|
19182
|
+
return res;
|
19183
|
+
}
|
19184
|
+
if (res = tryNodeResolve(id, importer, options, depsOptimizer, external)) {
|
19185
|
+
return res;
|
19186
|
+
}
|
19187
|
+
if (currentEnvironmentOptions.consumer === "server" && isBuiltin(options.builtins, id)) {
|
19188
|
+
return options.idOnly ? id : { id, external: true, moduleSideEffects: false };
|
19189
|
+
} else if (currentEnvironmentOptions.consumer === "server" && isNodeLikeBuiltin(id)) {
|
19190
|
+
if (!(options.external === true || options.external.includes(id))) {
|
19191
|
+
let message = `Automatically externalized node built-in module "${id}"`;
|
19192
|
+
if (importer) {
|
19193
|
+
message += ` imported from "${path$d.relative(
|
19194
|
+
process.cwd(),
|
19195
|
+
importer
|
19196
|
+
)}"`;
|
19197
|
+
}
|
19198
|
+
message += `. Consider adding it to environments.${this.environment.name}.external if it is intended.`;
|
19199
|
+
this.warn(message);
|
19200
|
+
}
|
19201
|
+
return options.idOnly ? id : { id, external: true, moduleSideEffects: false };
|
19202
|
+
} else if (currentEnvironmentOptions.consumer === "client" && isNodeLikeBuiltin(id)) {
|
19203
|
+
if (options.noExternal === true && // if both noExternal and external are true, noExternal will take the higher priority and bundle it.
|
19204
|
+
// only if the id is explicitly listed in external, we will externalize it and skip this error.
|
19205
|
+
(options.external === true || !options.external.includes(id))) {
|
19206
|
+
let message = `Cannot bundle built-in module "${id}"`;
|
19207
|
+
if (importer) {
|
19208
|
+
message += ` imported from "${path$d.relative(
|
19209
|
+
process.cwd(),
|
19210
|
+
importer
|
19211
|
+
)}"`;
|
19212
|
+
}
|
19213
|
+
message += `. Consider disabling environments.${this.environment.name}.noExternal or remove the built-in dependency.`;
|
19214
|
+
this.error(message);
|
19215
|
+
}
|
19216
|
+
if (!asSrc) {
|
19217
|
+
debug$d?.(
|
19218
|
+
`externalized node built-in "${id}" to empty module. (imported by: ${colors$1.white(colors$1.dim(importer))})`
|
19219
|
+
);
|
19220
|
+
} else if (isProduction) {
|
19221
|
+
this.warn(
|
19222
|
+
`Module "${id}" has been externalized for browser compatibility, imported by "${importer}". See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.`
|
19223
|
+
);
|
19224
|
+
}
|
19225
|
+
return isProduction ? browserExternalId : `${browserExternalId}:${id}`;
|
19226
|
+
}
|
19227
|
+
}
|
19228
|
+
debug$d?.(`[fallthrough] ${colors$1.dim(id)}`);
|
19229
|
+
},
|
19230
|
+
load(id) {
|
19231
|
+
if (id.startsWith(browserExternalId)) {
|
19232
|
+
if (isProduction) {
|
19233
|
+
return `export default {}`;
|
19234
|
+
} else {
|
19235
|
+
id = id.slice(browserExternalId.length + 1);
|
19236
|
+
return `export default new Proxy({}, {
|
19237
|
+
get(_, key) {
|
19238
|
+
throw new Error(\`Module "${id}" has been externalized for browser compatibility. Cannot access "${id}.\${key}" in client code. See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.\`)
|
19239
|
+
}
|
19240
|
+
})`;
|
19241
|
+
}
|
19242
|
+
}
|
19243
|
+
if (id.startsWith(optionalPeerDepId)) {
|
19244
|
+
if (isProduction) {
|
19245
|
+
return `export default {}`;
|
19246
|
+
} else {
|
19247
|
+
const [, peerDep, parentDep] = id.split(":");
|
19248
|
+
return `throw new Error(\`Could not resolve "${peerDep}" imported by "${parentDep}". Is it installed?\`)`;
|
19249
|
+
}
|
19113
19250
|
}
|
19114
|
-
|
19115
|
-
}).finally(() => {
|
19116
|
-
return disposeContext();
|
19117
|
-
});
|
19118
|
-
});
|
19119
|
-
runResult.catch(() => {
|
19120
|
-
cleanUp();
|
19121
|
-
});
|
19122
|
-
return {
|
19123
|
-
async cancel() {
|
19124
|
-
optimizerContext.cancelled = true;
|
19125
|
-
const { context } = await preparedRun;
|
19126
|
-
await context?.cancel();
|
19127
|
-
cleanUp();
|
19128
|
-
},
|
19129
|
-
result: runResult
|
19251
|
+
}
|
19130
19252
|
};
|
19131
19253
|
}
|
19132
|
-
|
19133
|
-
|
19134
|
-
const
|
19135
|
-
const
|
19136
|
-
|
19137
|
-
|
19138
|
-
|
19139
|
-
|
19140
|
-
|
19141
|
-
|
19142
|
-
|
19143
|
-
|
19144
|
-
...esbuildOptions.loader
|
19145
|
-
};
|
19146
|
-
}
|
19147
|
-
const flatId = flattenId(id);
|
19148
|
-
flatIdDeps[flatId] = src;
|
19149
|
-
idToExports[id] = exportsData;
|
19150
|
-
})
|
19254
|
+
function resolveSubpathImports(id, importer, options) {
|
19255
|
+
if (!importer || !id.startsWith(subpathImportsPrefix)) return;
|
19256
|
+
const basedir = path$d.dirname(importer);
|
19257
|
+
const pkgData = findNearestPackageData(basedir, options.packageCache);
|
19258
|
+
if (!pkgData) return;
|
19259
|
+
let { file: idWithoutPostfix, postfix } = splitFileAndPostfix(id.slice(1));
|
19260
|
+
idWithoutPostfix = "#" + idWithoutPostfix;
|
19261
|
+
let importsPath = resolveExportsOrImports(
|
19262
|
+
pkgData.data,
|
19263
|
+
idWithoutPostfix,
|
19264
|
+
options,
|
19265
|
+
"imports"
|
19151
19266
|
);
|
19152
|
-
if (
|
19153
|
-
|
19154
|
-
"
|
19155
|
-
|
19156
|
-
|
19157
|
-
"process.env.NODE_ENV"
|
19158
|
-
) : JSON.stringify(process.env.NODE_ENV || environment.config.mode)
|
19159
|
-
};
|
19160
|
-
const platform = optimizeDeps2.esbuildOptions?.platform ?? // We generally don't want to use platform 'neutral', as esbuild has custom handling
|
19161
|
-
// when the platform is 'node' or 'browser' that can't be emulated by using mainFields
|
19162
|
-
// and conditions
|
19163
|
-
(environment.config.consumer === "client" || environment.config.ssr.target === "webworker" ? "browser" : "node");
|
19164
|
-
const external = [...optimizeDeps2.exclude ?? []];
|
19165
|
-
const plugins = [...pluginsFromConfig];
|
19166
|
-
if (external.length) {
|
19167
|
-
plugins.push(esbuildCjsExternalPlugin(external, platform));
|
19267
|
+
if (importsPath?.[0] === ".") {
|
19268
|
+
importsPath = path$d.relative(basedir, path$d.join(pkgData.dir, importsPath));
|
19269
|
+
if (importsPath[0] !== ".") {
|
19270
|
+
importsPath = `./${importsPath}`;
|
19271
|
+
}
|
19168
19272
|
}
|
19169
|
-
|
19170
|
-
|
19171
|
-
|
19172
|
-
|
19173
|
-
|
19174
|
-
|
19175
|
-
|
19176
|
-
|
19177
|
-
|
19178
|
-
|
19179
|
-
js: `import { createRequire } from 'module';const require = createRequire(import.meta.url);`
|
19180
|
-
} : void 0,
|
19181
|
-
target: ESBUILD_MODULES_TARGET,
|
19182
|
-
external,
|
19183
|
-
logLevel: "error",
|
19184
|
-
splitting: true,
|
19185
|
-
sourcemap: true,
|
19186
|
-
outdir: processingCacheDir,
|
19187
|
-
ignoreAnnotations: true,
|
19188
|
-
metafile: true,
|
19189
|
-
plugins,
|
19190
|
-
charset: "utf8",
|
19191
|
-
...esbuildOptions,
|
19192
|
-
supported: {
|
19193
|
-
...defaultEsbuildSupported,
|
19194
|
-
...esbuildOptions.supported
|
19273
|
+
return importsPath + postfix;
|
19274
|
+
}
|
19275
|
+
function ensureVersionQuery(resolved, id, options, depsOptimizer) {
|
19276
|
+
if (!options.isBuild && !options.scan && depsOptimizer && !(resolved === normalizedClientEntry$1 || resolved === normalizedEnvEntry$1)) {
|
19277
|
+
const isNodeModule = isInNodeModules$1(id) || isInNodeModules$1(resolved);
|
19278
|
+
if (isNodeModule && !DEP_VERSION_RE.test(resolved)) {
|
19279
|
+
const versionHash = depsOptimizer.metadata.browserHash;
|
19280
|
+
if (versionHash && isOptimizable(resolved, depsOptimizer.options)) {
|
19281
|
+
resolved = injectQuery(resolved, `v=${versionHash}`);
|
19282
|
+
}
|
19195
19283
|
}
|
19196
|
-
}
|
19197
|
-
return
|
19284
|
+
}
|
19285
|
+
return resolved;
|
19198
19286
|
}
|
19199
|
-
|
19200
|
-
const
|
19201
|
-
|
19202
|
-
|
19203
|
-
|
19204
|
-
|
19205
|
-
|
19206
|
-
|
19207
|
-
|
19208
|
-
|
19287
|
+
function tryFsResolve(fsPath, options, tryIndex = true, skipPackageJson = false) {
|
19288
|
+
const hashIndex = fsPath.indexOf("#");
|
19289
|
+
if (hashIndex >= 0 && isInNodeModules$1(fsPath)) {
|
19290
|
+
const queryIndex = fsPath.indexOf("?");
|
19291
|
+
if (queryIndex < 0 || queryIndex > hashIndex) {
|
19292
|
+
const file2 = queryIndex > hashIndex ? fsPath.slice(0, queryIndex) : fsPath;
|
19293
|
+
const res2 = tryCleanFsResolve(file2, options, tryIndex, skipPackageJson);
|
19294
|
+
if (res2) return res2 + fsPath.slice(file2.length);
|
19295
|
+
}
|
19296
|
+
}
|
19297
|
+
const { file, postfix } = splitFileAndPostfix(fsPath);
|
19298
|
+
const res = tryCleanFsResolve(file, options, tryIndex, skipPackageJson);
|
19299
|
+
if (res) return res + postfix;
|
19300
|
+
}
|
19301
|
+
const knownTsOutputRE = /\.(?:js|mjs|cjs|jsx)$/;
|
19302
|
+
const isPossibleTsOutput = (url) => knownTsOutputRE.test(url);
|
19303
|
+
function tryCleanFsResolve(file, options, tryIndex = true, skipPackageJson = false) {
|
19304
|
+
const { tryPrefix, extensions, preserveSymlinks } = options;
|
19305
|
+
const fileResult = tryResolveRealFileOrType(file, options.preserveSymlinks);
|
19306
|
+
if (fileResult?.path) return fileResult.path;
|
19307
|
+
let res;
|
19308
|
+
const possibleJsToTs = isPossibleTsOutput(file);
|
19309
|
+
if (possibleJsToTs || options.extensions.length || tryPrefix) {
|
19310
|
+
const dirPath = path$d.dirname(file);
|
19311
|
+
if (isDirectory(dirPath)) {
|
19312
|
+
if (possibleJsToTs) {
|
19313
|
+
const fileExt = path$d.extname(file);
|
19314
|
+
const fileName = file.slice(0, -fileExt.length);
|
19315
|
+
if (res = tryResolveRealFile(
|
19316
|
+
fileName + fileExt.replace("js", "ts"),
|
19317
|
+
preserveSymlinks
|
19318
|
+
))
|
19319
|
+
return res;
|
19320
|
+
if (fileExt === ".js" && (res = tryResolveRealFile(fileName + ".tsx", preserveSymlinks)))
|
19321
|
+
return res;
|
19209
19322
|
}
|
19210
|
-
|
19211
|
-
|
19212
|
-
|
19213
|
-
|
19214
|
-
|
19215
|
-
|
19216
|
-
|
19217
|
-
|
19323
|
+
if (res = tryResolveRealFileWithExtensions(
|
19324
|
+
file,
|
19325
|
+
extensions,
|
19326
|
+
preserveSymlinks
|
19327
|
+
))
|
19328
|
+
return res;
|
19329
|
+
if (tryPrefix) {
|
19330
|
+
const prefixed = `${dirPath}/${options.tryPrefix}${path$d.basename(file)}`;
|
19331
|
+
if (res = tryResolveRealFile(prefixed, preserveSymlinks)) return res;
|
19332
|
+
if (res = tryResolveRealFileWithExtensions(
|
19333
|
+
prefixed,
|
19334
|
+
extensions,
|
19335
|
+
preserveSymlinks
|
19336
|
+
))
|
19337
|
+
return res;
|
19218
19338
|
}
|
19219
19339
|
}
|
19220
|
-
|
19221
|
-
|
19222
|
-
|
19223
|
-
|
19224
|
-
|
19225
|
-
|
19226
|
-
|
19227
|
-
|
19228
|
-
|
19229
|
-
unableToOptimize(id, "Cannot optimize dependency");
|
19340
|
+
}
|
19341
|
+
if (tryIndex && fileResult?.type === "directory") {
|
19342
|
+
const dirPath = file;
|
19343
|
+
if (!skipPackageJson) {
|
19344
|
+
let pkgPath = `${dirPath}/package.json`;
|
19345
|
+
try {
|
19346
|
+
if (fs__default.existsSync(pkgPath)) {
|
19347
|
+
if (!options.preserveSymlinks) {
|
19348
|
+
pkgPath = safeRealpathSync(pkgPath);
|
19230
19349
|
}
|
19231
|
-
|
19232
|
-
|
19350
|
+
const pkg = loadPackageData(pkgPath);
|
19351
|
+
return resolvePackageEntry(dirPath, pkg, options);
|
19233
19352
|
}
|
19353
|
+
} catch (e) {
|
19354
|
+
if (e.code !== ERR_RESOLVE_PACKAGE_ENTRY_FAIL && e.code !== "ENOENT")
|
19355
|
+
throw e;
|
19234
19356
|
}
|
19235
19357
|
}
|
19358
|
+
if (res = tryResolveRealFileWithExtensions(
|
19359
|
+
`${dirPath}/index`,
|
19360
|
+
extensions,
|
19361
|
+
preserveSymlinks
|
19362
|
+
))
|
19363
|
+
return res;
|
19364
|
+
if (tryPrefix) {
|
19365
|
+
if (res = tryResolveRealFileWithExtensions(
|
19366
|
+
`${dirPath}/${options.tryPrefix}index`,
|
19367
|
+
extensions,
|
19368
|
+
preserveSymlinks
|
19369
|
+
))
|
19370
|
+
return res;
|
19371
|
+
}
|
19236
19372
|
}
|
19237
19373
|
}
|
19238
|
-
function
|
19239
|
-
const
|
19240
|
-
|
19241
|
-
|
19374
|
+
function tryNodeResolve(id, importer, options, depsOptimizer, externalize) {
|
19375
|
+
const { root, dedupe, isBuild, preserveSymlinks, packageCache } = options;
|
19376
|
+
const deepMatch = deepImportRE.exec(id);
|
19377
|
+
const pkgId = deepMatch ? deepMatch[1] || deepMatch[2] : cleanUrl(id);
|
19378
|
+
let basedir;
|
19379
|
+
if (dedupe.includes(pkgId)) {
|
19380
|
+
basedir = root;
|
19381
|
+
} else if (importer && path$d.isAbsolute(importer) && // css processing appends `*` for importer
|
19382
|
+
(importer.endsWith("*") || fs__default.existsSync(cleanUrl(importer)))) {
|
19383
|
+
basedir = path$d.dirname(importer);
|
19384
|
+
} else {
|
19385
|
+
basedir = root;
|
19242
19386
|
}
|
19243
|
-
|
19244
|
-
|
19245
|
-
|
19246
|
-
|
19247
|
-
|
19248
|
-
|
19249
|
-
|
19250
|
-
|
19251
|
-
|
19252
|
-
|
19253
|
-
|
19254
|
-
|
19255
|
-
|
19256
|
-
|
19257
|
-
|
19258
|
-
}
|
19259
|
-
|
19260
|
-
|
19261
|
-
|
19262
|
-
);
|
19263
|
-
}
|
19264
|
-
function getDepsCacheDirPrefix(environment) {
|
19265
|
-
return normalizePath$3(path$d.resolve(environment.config.cacheDir, "deps"));
|
19266
|
-
}
|
19267
|
-
function createIsOptimizedDepFile(environment) {
|
19268
|
-
const depsCacheDirPrefix = getDepsCacheDirPrefix(environment);
|
19269
|
-
return (id) => id.startsWith(depsCacheDirPrefix);
|
19270
|
-
}
|
19271
|
-
function createIsOptimizedDepUrl(environment) {
|
19272
|
-
const { root } = environment.config;
|
19273
|
-
const depsCacheDir = getDepsCacheDirPrefix(environment);
|
19274
|
-
const depsCacheDirRelative = normalizePath$3(path$d.relative(root, depsCacheDir));
|
19275
|
-
const depsCacheDirPrefix = depsCacheDirRelative.startsWith("../") ? (
|
19276
|
-
// if the cache directory is outside root, the url prefix would be something
|
19277
|
-
// like '/@fs/absolute/path/to/node_modules/.vite'
|
19278
|
-
`/@fs/${removeLeadingSlash(normalizePath$3(depsCacheDir))}`
|
19279
|
-
) : (
|
19280
|
-
// if the cache directory is inside root, the url prefix would be something
|
19281
|
-
// like '/node_modules/.vite'
|
19282
|
-
`/${depsCacheDirRelative}`
|
19283
|
-
);
|
19284
|
-
return function isOptimizedDepUrl(url) {
|
19285
|
-
return url.startsWith(depsCacheDirPrefix);
|
19286
|
-
};
|
19287
|
-
}
|
19288
|
-
function parseDepsOptimizerMetadata(jsonMetadata, depsCacheDir) {
|
19289
|
-
const { hash, lockfileHash, configHash, browserHash, optimized, chunks } = JSON.parse(jsonMetadata, (key, value) => {
|
19290
|
-
if (key === "file" || key === "src") {
|
19291
|
-
return normalizePath$3(path$d.resolve(depsCacheDir, value));
|
19387
|
+
const isModuleBuiltin = (id2) => isBuiltin(options.builtins, id2);
|
19388
|
+
let selfPkg = null;
|
19389
|
+
if (!isModuleBuiltin(id) && !id.includes("\0") && bareImportRE.test(id)) {
|
19390
|
+
const selfPackageData = findNearestPackageData(basedir, packageCache);
|
19391
|
+
selfPkg = selfPackageData?.data.exports && selfPackageData.data.name === pkgId ? selfPackageData : null;
|
19392
|
+
}
|
19393
|
+
const pkg = selfPkg || resolvePackageData(pkgId, basedir, preserveSymlinks, packageCache);
|
19394
|
+
if (!pkg) {
|
19395
|
+
if (basedir !== root && // root has no peer dep
|
19396
|
+
!isModuleBuiltin(id) && !id.includes("\0") && bareImportRE.test(id)) {
|
19397
|
+
const mainPkg = findNearestMainPackageData(basedir, packageCache)?.data;
|
19398
|
+
if (mainPkg) {
|
19399
|
+
const pkgName = getNpmPackageName(id);
|
19400
|
+
if (pkgName != null && mainPkg.peerDependencies?.[pkgName] && mainPkg.peerDependenciesMeta?.[pkgName]?.optional) {
|
19401
|
+
return {
|
19402
|
+
id: `${optionalPeerDepId}:${id}:${mainPkg.name}`
|
19403
|
+
};
|
19404
|
+
}
|
19405
|
+
}
|
19292
19406
|
}
|
19293
|
-
return value;
|
19294
|
-
});
|
19295
|
-
if (!chunks || Object.values(optimized).some((depInfo) => !depInfo.fileHash)) {
|
19296
19407
|
return;
|
19297
19408
|
}
|
19298
|
-
const
|
19299
|
-
|
19300
|
-
|
19301
|
-
|
19302
|
-
|
19303
|
-
optimized: {},
|
19304
|
-
discovered: {},
|
19305
|
-
chunks: {},
|
19306
|
-
depInfoList: []
|
19307
|
-
};
|
19308
|
-
for (const id of Object.keys(optimized)) {
|
19309
|
-
addOptimizedDepInfo(metadata, "optimized", {
|
19310
|
-
...optimized[id],
|
19311
|
-
id,
|
19312
|
-
browserHash
|
19313
|
-
});
|
19314
|
-
}
|
19315
|
-
for (const id of Object.keys(chunks)) {
|
19316
|
-
addOptimizedDepInfo(metadata, "chunks", {
|
19317
|
-
...chunks[id],
|
19318
|
-
id,
|
19319
|
-
browserHash,
|
19320
|
-
needsInterop: false
|
19321
|
-
});
|
19409
|
+
const resolveId = deepMatch ? resolveDeepImport : resolvePackageEntry;
|
19410
|
+
const unresolvedId = deepMatch ? "." + id.slice(pkgId.length) : id;
|
19411
|
+
let resolved = resolveId(unresolvedId, pkg, options);
|
19412
|
+
if (!resolved) {
|
19413
|
+
return;
|
19322
19414
|
}
|
19323
|
-
|
19324
|
-
|
19325
|
-
|
19326
|
-
|
19327
|
-
|
19328
|
-
|
19329
|
-
|
19330
|
-
|
19331
|
-
|
19332
|
-
|
19333
|
-
|
19334
|
-
|
19335
|
-
|
19336
|
-
|
19337
|
-
|
19338
|
-
src,
|
19339
|
-
file,
|
19340
|
-
fileHash,
|
19341
|
-
needsInterop: needsInterop2
|
19342
|
-
}
|
19343
|
-
]
|
19344
|
-
)
|
19345
|
-
),
|
19346
|
-
chunks: Object.fromEntries(
|
19347
|
-
Object.values(chunks).map(({ id, file }) => [id, { file }])
|
19348
|
-
)
|
19349
|
-
},
|
19350
|
-
(key, value) => {
|
19351
|
-
if (key === "file" || key === "src") {
|
19352
|
-
return normalizePath$3(path$d.relative(depsCacheDir, value));
|
19415
|
+
const processResult = (resolved2) => {
|
19416
|
+
if (!externalize) {
|
19417
|
+
return resolved2;
|
19418
|
+
}
|
19419
|
+
if (!canExternalizeFile(resolved2.id)) {
|
19420
|
+
return resolved2;
|
19421
|
+
}
|
19422
|
+
let resolvedId = id;
|
19423
|
+
if (deepMatch && !pkg.data.exports && path$d.extname(id) !== path$d.extname(resolved2.id)) {
|
19424
|
+
const index = resolved2.id.indexOf(id);
|
19425
|
+
if (index > -1) {
|
19426
|
+
resolvedId = resolved2.id.slice(index);
|
19427
|
+
debug$d?.(
|
19428
|
+
`[processResult] ${colors$1.cyan(id)} -> ${colors$1.dim(resolvedId)}`
|
19429
|
+
);
|
19353
19430
|
}
|
19354
|
-
return value;
|
19355
|
-
},
|
19356
|
-
2
|
19357
|
-
);
|
19358
|
-
}
|
19359
|
-
function esbuildOutputFromId(outputs, id, cacheDirOutputPath) {
|
19360
|
-
const cwd = process.cwd();
|
19361
|
-
const flatId = flattenId(id) + ".js";
|
19362
|
-
const normalizedOutputPath = normalizePath$3(
|
19363
|
-
path$d.relative(cwd, path$d.join(cacheDirOutputPath, flatId))
|
19364
|
-
);
|
19365
|
-
const output = outputs[normalizedOutputPath];
|
19366
|
-
if (output) {
|
19367
|
-
return output;
|
19368
|
-
}
|
19369
|
-
for (const [key, value] of Object.entries(outputs)) {
|
19370
|
-
if (normalizePath$3(path$d.relative(cwd, key)) === normalizedOutputPath) {
|
19371
|
-
return value;
|
19372
19431
|
}
|
19373
|
-
|
19374
|
-
}
|
19375
|
-
|
19376
|
-
|
19377
|
-
|
19378
|
-
|
19379
|
-
if (optimizeDeps2.extensions?.some((ext) => filePath.endsWith(ext))) {
|
19380
|
-
const result = await build$b({
|
19381
|
-
...esbuildOptions,
|
19382
|
-
entryPoints: [filePath],
|
19383
|
-
write: false,
|
19384
|
-
format: "esm"
|
19432
|
+
return { ...resolved2, id: resolvedId, external: true };
|
19433
|
+
};
|
19434
|
+
if (!options.idOnly && (!options.scan && isBuild || externalize)) {
|
19435
|
+
return processResult({
|
19436
|
+
id: resolved,
|
19437
|
+
moduleSideEffects: pkg.hasSideEffects(resolved)
|
19385
19438
|
});
|
19386
|
-
const [, exports2, , hasModuleSyntax2] = parse$e(result.outputFiles[0].text);
|
19387
|
-
return {
|
19388
|
-
hasModuleSyntax: hasModuleSyntax2,
|
19389
|
-
exports: exports2.map((e) => e.n)
|
19390
|
-
};
|
19391
19439
|
}
|
19392
|
-
|
19393
|
-
|
19394
|
-
|
19395
|
-
|
19396
|
-
parseResult = parse$e(entryContent);
|
19397
|
-
} catch {
|
19398
|
-
const loader = esbuildOptions.loader?.[path$d.extname(filePath)] || "jsx";
|
19399
|
-
debug$d?.(
|
19400
|
-
`Unable to parse: ${filePath}.
|
19401
|
-
Trying again with a ${loader} transform.`
|
19402
|
-
);
|
19403
|
-
const transformed = await transformWithEsbuild(
|
19404
|
-
entryContent,
|
19405
|
-
filePath,
|
19406
|
-
{ loader },
|
19407
|
-
void 0,
|
19408
|
-
environment.config
|
19409
|
-
);
|
19410
|
-
parseResult = parse$e(transformed.code);
|
19411
|
-
usedJsxLoader = true;
|
19440
|
+
if (!isInNodeModules$1(resolved) || // linked
|
19441
|
+
!depsOptimizer || // resolving before listening to the server
|
19442
|
+
options.scan) {
|
19443
|
+
return { id: resolved };
|
19412
19444
|
}
|
19413
|
-
const
|
19414
|
-
const
|
19415
|
-
|
19416
|
-
|
19417
|
-
|
19418
|
-
|
19419
|
-
|
19420
|
-
}
|
19421
|
-
|
19422
|
-
|
19423
|
-
|
19445
|
+
const isJsType = isOptimizable(resolved, depsOptimizer.options);
|
19446
|
+
const exclude = depsOptimizer.options.exclude;
|
19447
|
+
const skipOptimization = depsOptimizer.options.noDiscovery || !isJsType || importer && isInNodeModules$1(importer) || exclude?.includes(pkgId) || exclude?.includes(id) || SPECIAL_QUERY_RE.test(resolved);
|
19448
|
+
if (skipOptimization) {
|
19449
|
+
const versionHash = depsOptimizer.metadata.browserHash;
|
19450
|
+
if (versionHash && isJsType) {
|
19451
|
+
resolved = injectQuery(resolved, `v=${versionHash}`);
|
19452
|
+
}
|
19453
|
+
} else {
|
19454
|
+
const optimizedInfo = depsOptimizer.registerMissingImport(id, resolved);
|
19455
|
+
resolved = depsOptimizer.getOptimizedDepId(optimizedInfo);
|
19424
19456
|
}
|
19425
|
-
|
19426
|
-
|
19427
|
-
|
19457
|
+
return { id: resolved };
|
19458
|
+
}
|
19459
|
+
async function tryOptimizedResolve(depsOptimizer, id, importer, preserveSymlinks, packageCache) {
|
19460
|
+
await depsOptimizer.scanProcessing;
|
19461
|
+
const metadata = depsOptimizer.metadata;
|
19462
|
+
const depInfo = optimizedDepInfoFromId(metadata, id);
|
19463
|
+
if (depInfo) {
|
19464
|
+
return depsOptimizer.getOptimizedDepId(depInfo);
|
19428
19465
|
}
|
19429
|
-
if (
|
19430
|
-
|
19431
|
-
|
19432
|
-
|
19466
|
+
if (!importer) return;
|
19467
|
+
let idPkgDir;
|
19468
|
+
const nestedIdMatch = `> ${id}`;
|
19469
|
+
for (const optimizedData of metadata.depInfoList) {
|
19470
|
+
if (!optimizedData.src) continue;
|
19471
|
+
if (!optimizedData.id.endsWith(nestedIdMatch)) continue;
|
19472
|
+
if (idPkgDir == null) {
|
19473
|
+
const pkgName = getNpmPackageName(id);
|
19474
|
+
if (!pkgName) break;
|
19475
|
+
idPkgDir = resolvePackageData(
|
19476
|
+
pkgName,
|
19477
|
+
importer,
|
19478
|
+
preserveSymlinks,
|
19479
|
+
packageCache
|
19480
|
+
)?.dir;
|
19481
|
+
if (idPkgDir == null) break;
|
19482
|
+
idPkgDir = normalizePath$3(idPkgDir);
|
19483
|
+
}
|
19484
|
+
if (optimizedData.src.startsWith(withTrailingSlash(idPkgDir))) {
|
19485
|
+
return depsOptimizer.getOptimizedDepId(optimizedData);
|
19433
19486
|
}
|
19434
19487
|
}
|
19435
|
-
return false;
|
19436
|
-
}
|
19437
|
-
function isSingleDefaultExport(exports) {
|
19438
|
-
return exports.length === 1 && exports[0] === "default";
|
19439
19488
|
}
|
19440
|
-
|
19441
|
-
{
|
19442
|
-
|
19443
|
-
|
19444
|
-
|
19445
|
-
},
|
19446
|
-
{
|
19447
|
-
// Yarn non-PnP
|
19448
|
-
path: "node_modules/.yarn-state.yml",
|
19449
|
-
checkPatchesDir: false,
|
19450
|
-
manager: "yarn"
|
19451
|
-
},
|
19452
|
-
{
|
19453
|
-
// Yarn v3+ PnP
|
19454
|
-
path: ".pnp.cjs",
|
19455
|
-
checkPatchesDir: ".yarn/patches",
|
19456
|
-
manager: "yarn"
|
19457
|
-
},
|
19458
|
-
{
|
19459
|
-
// Yarn v2 PnP
|
19460
|
-
path: ".pnp.js",
|
19461
|
-
checkPatchesDir: ".yarn/patches",
|
19462
|
-
manager: "yarn"
|
19463
|
-
},
|
19464
|
-
{
|
19465
|
-
// yarn 1
|
19466
|
-
path: "node_modules/.yarn-integrity",
|
19467
|
-
checkPatchesDir: "patches",
|
19468
|
-
manager: "yarn"
|
19469
|
-
},
|
19470
|
-
{
|
19471
|
-
path: "node_modules/.pnpm/lock.yaml",
|
19472
|
-
// Included in lockfile
|
19473
|
-
checkPatchesDir: false,
|
19474
|
-
manager: "pnpm"
|
19475
|
-
},
|
19476
|
-
{
|
19477
|
-
path: "bun.lock",
|
19478
|
-
checkPatchesDir: "patches",
|
19479
|
-
manager: "bun"
|
19480
|
-
},
|
19481
|
-
{
|
19482
|
-
path: "bun.lockb",
|
19483
|
-
checkPatchesDir: "patches",
|
19484
|
-
manager: "bun"
|
19489
|
+
function resolvePackageEntry(id, { dir, data, setResolvedCache, getResolvedCache }, options) {
|
19490
|
+
const { file: idWithoutPostfix, postfix } = splitFileAndPostfix(id);
|
19491
|
+
const cached = getResolvedCache(".", options);
|
19492
|
+
if (cached) {
|
19493
|
+
return cached + postfix;
|
19485
19494
|
}
|
19486
|
-
|
19487
|
-
|
19488
|
-
|
19489
|
-
|
19490
|
-
|
19491
|
-
|
19492
|
-
|
19493
|
-
|
19494
|
-
|
19495
|
-
|
19496
|
-
|
19497
|
-
|
19498
|
-
|
19499
|
-
|
19500
|
-
|
19501
|
-
include: optimizeDeps2.include ? unique(optimizeDeps2.include).sort() : void 0,
|
19502
|
-
exclude: optimizeDeps2.exclude ? unique(optimizeDeps2.exclude).sort() : void 0,
|
19503
|
-
esbuildOptions: {
|
19504
|
-
...optimizeDeps2.esbuildOptions,
|
19505
|
-
plugins: optimizeDeps2.esbuildOptions?.plugins?.map((p) => p.name)
|
19495
|
+
try {
|
19496
|
+
let entryPoint;
|
19497
|
+
if (data.exports) {
|
19498
|
+
entryPoint = resolveExportsOrImports(data, ".", options, "exports");
|
19499
|
+
}
|
19500
|
+
if (!entryPoint) {
|
19501
|
+
for (const field of options.mainFields) {
|
19502
|
+
if (field === "browser") {
|
19503
|
+
entryPoint = tryResolveBrowserEntry(dir, data, options);
|
19504
|
+
if (entryPoint) {
|
19505
|
+
break;
|
19506
|
+
}
|
19507
|
+
} else if (typeof data[field] === "string") {
|
19508
|
+
entryPoint = data[field];
|
19509
|
+
break;
|
19506
19510
|
}
|
19507
19511
|
}
|
19508
|
-
},
|
19509
|
-
(_, value) => {
|
19510
|
-
if (typeof value === "function" || value instanceof RegExp) {
|
19511
|
-
return value.toString();
|
19512
|
-
}
|
19513
|
-
return value;
|
19514
19512
|
}
|
19515
|
-
|
19516
|
-
|
19517
|
-
|
19518
|
-
|
19519
|
-
|
19520
|
-
|
19521
|
-
|
19522
|
-
|
19523
|
-
|
19524
|
-
|
19525
|
-
|
19526
|
-
|
19527
|
-
|
19528
|
-
const
|
19529
|
-
|
19530
|
-
|
19513
|
+
entryPoint ||= data.main;
|
19514
|
+
const entryPoints = entryPoint ? [entryPoint] : ["index.js", "index.json", "index.node"];
|
19515
|
+
for (let entry of entryPoints) {
|
19516
|
+
let skipPackageJson = false;
|
19517
|
+
if (options.mainFields[0] === "sass" && !options.extensions.includes(path$d.extname(entry))) {
|
19518
|
+
entry = "";
|
19519
|
+
skipPackageJson = true;
|
19520
|
+
} else {
|
19521
|
+
const { browser: browserField } = data;
|
19522
|
+
if (options.mainFields.includes("browser") && isObject$2(browserField)) {
|
19523
|
+
entry = mapWithBrowserField(entry, browserField) || entry;
|
19524
|
+
}
|
19525
|
+
}
|
19526
|
+
const entryPointPath = path$d.join(dir, entry);
|
19527
|
+
const resolvedEntryPoint = tryFsResolve(
|
19528
|
+
entryPointPath,
|
19529
|
+
options,
|
19530
|
+
true,
|
19531
|
+
skipPackageJson
|
19531
19532
|
);
|
19532
|
-
|
19533
|
-
|
19534
|
-
|
19533
|
+
if (resolvedEntryPoint) {
|
19534
|
+
debug$d?.(
|
19535
|
+
`[package entry] ${colors$1.cyan(idWithoutPostfix)} -> ${colors$1.dim(
|
19536
|
+
resolvedEntryPoint
|
19537
|
+
)}${postfix !== "" ? ` (postfix: ${postfix})` : ""}`
|
19538
|
+
);
|
19539
|
+
setResolvedCache(".", resolvedEntryPoint, options);
|
19540
|
+
return resolvedEntryPoint + postfix;
|
19535
19541
|
}
|
19536
19542
|
}
|
19543
|
+
} catch (e) {
|
19544
|
+
packageEntryFailure(id, e.message);
|
19537
19545
|
}
|
19538
|
-
|
19539
|
-
}
|
19540
|
-
function getDepHash(environment) {
|
19541
|
-
const lockfileHash = getLockfileHash(environment);
|
19542
|
-
const configHash = getConfigHash(environment);
|
19543
|
-
const hash = getHash(lockfileHash + configHash);
|
19544
|
-
return {
|
19545
|
-
hash,
|
19546
|
-
lockfileHash,
|
19547
|
-
configHash
|
19548
|
-
};
|
19549
|
-
}
|
19550
|
-
function getOptimizedBrowserHash(hash, deps, timestamp = "") {
|
19551
|
-
return getHash(hash + JSON.stringify(deps) + timestamp);
|
19552
|
-
}
|
19553
|
-
function optimizedDepInfoFromId(metadata, id) {
|
19554
|
-
return metadata.optimized[id] || metadata.discovered[id] || metadata.chunks[id];
|
19546
|
+
packageEntryFailure(id);
|
19555
19547
|
}
|
19556
|
-
function
|
19557
|
-
|
19548
|
+
function packageEntryFailure(id, details) {
|
19549
|
+
const err = new Error(
|
19550
|
+
`Failed to resolve entry for package "${id}". The package may have incorrect main/module/exports specified in its package.json` + (details ? ": " + details : ".")
|
19551
|
+
);
|
19552
|
+
err.code = ERR_RESOLVE_PACKAGE_ENTRY_FAIL;
|
19553
|
+
throw err;
|
19558
19554
|
}
|
19559
|
-
function
|
19560
|
-
|
19561
|
-
|
19562
|
-
|
19563
|
-
return info;
|
19555
|
+
function resolveExportsOrImports(pkg, key, options, type) {
|
19556
|
+
const conditions = options.conditions.map((condition) => {
|
19557
|
+
if (condition === DEV_PROD_CONDITION) {
|
19558
|
+
return options.isProduction ? "production" : "development";
|
19564
19559
|
}
|
19560
|
+
return condition;
|
19561
|
+
});
|
19562
|
+
if (options.isRequire) {
|
19563
|
+
conditions.push("require");
|
19564
|
+
} else {
|
19565
|
+
conditions.push("import");
|
19565
19566
|
}
|
19567
|
+
const fn = type === "imports" ? f : o;
|
19568
|
+
const result = fn(pkg, key, { conditions, unsafe: true });
|
19569
|
+
return result ? result[0] : void 0;
|
19566
19570
|
}
|
19567
|
-
|
19568
|
-
const
|
19569
|
-
if (
|
19570
|
-
|
19571
|
-
|
19572
|
-
|
19573
|
-
|
19574
|
-
|
19571
|
+
function resolveDeepImport(id, { setResolvedCache, getResolvedCache, dir, data }, options) {
|
19572
|
+
const cache = getResolvedCache(id, options);
|
19573
|
+
if (cache) {
|
19574
|
+
return cache;
|
19575
|
+
}
|
19576
|
+
let relativeId = id;
|
19577
|
+
const { exports: exportsField, browser: browserField } = data;
|
19578
|
+
if (exportsField) {
|
19579
|
+
if (isObject$2(exportsField) && !Array.isArray(exportsField)) {
|
19580
|
+
const { file, postfix } = splitFileAndPostfix(relativeId);
|
19581
|
+
const exportsId = resolveExportsOrImports(data, file, options, "exports");
|
19582
|
+
if (exportsId !== void 0) {
|
19583
|
+
relativeId = exportsId + postfix;
|
19584
|
+
} else {
|
19585
|
+
relativeId = void 0;
|
19586
|
+
}
|
19587
|
+
} else {
|
19588
|
+
relativeId = void 0;
|
19589
|
+
}
|
19590
|
+
if (!relativeId) {
|
19591
|
+
throw new Error(
|
19592
|
+
`Package subpath '${relativeId}' is not defined by "exports" in ${path$d.join(dir, "package.json")}.`
|
19593
|
+
);
|
19594
|
+
}
|
19595
|
+
} else if (options.mainFields.includes("browser") && isObject$2(browserField)) {
|
19596
|
+
const { file, postfix } = splitFileAndPostfix(relativeId);
|
19597
|
+
const mapped = mapWithBrowserField(file, browserField);
|
19598
|
+
if (mapped) {
|
19599
|
+
relativeId = mapped + postfix;
|
19600
|
+
} else if (mapped === false) {
|
19601
|
+
setResolvedCache(id, browserExternalId, options);
|
19602
|
+
return browserExternalId;
|
19603
|
+
}
|
19604
|
+
}
|
19605
|
+
if (relativeId) {
|
19606
|
+
const resolved = tryFsResolve(
|
19607
|
+
path$d.join(dir, relativeId),
|
19608
|
+
options,
|
19609
|
+
!exportsField
|
19610
|
+
// try index only if no exports field
|
19575
19611
|
);
|
19612
|
+
if (resolved) {
|
19613
|
+
debug$d?.(
|
19614
|
+
`[node/deep-import] ${colors$1.cyan(id)} -> ${colors$1.dim(resolved)}`
|
19615
|
+
);
|
19616
|
+
setResolvedCache(id, resolved, options);
|
19617
|
+
return resolved;
|
19618
|
+
}
|
19576
19619
|
}
|
19577
|
-
return depInfo?.needsInterop;
|
19578
19620
|
}
|
19579
|
-
|
19580
|
-
|
19581
|
-
|
19582
|
-
|
19583
|
-
|
19584
|
-
|
19585
|
-
|
19586
|
-
|
19587
|
-
|
19588
|
-
|
19589
|
-
|
19590
|
-
|
19591
|
-
|
19621
|
+
function tryResolveBrowserMapping(id, importer, options, isFilePath, externalize) {
|
19622
|
+
let res;
|
19623
|
+
const pkg = importer && findNearestPackageData(path$d.dirname(importer), options.packageCache);
|
19624
|
+
if (pkg && isObject$2(pkg.data.browser)) {
|
19625
|
+
const mapId = isFilePath ? "./" + slash$1(path$d.relative(pkg.dir, id)) : id;
|
19626
|
+
const browserMappedPath = mapWithBrowserField(mapId, pkg.data.browser);
|
19627
|
+
if (browserMappedPath) {
|
19628
|
+
if (res = bareImportRE.test(browserMappedPath) ? tryNodeResolve(
|
19629
|
+
browserMappedPath,
|
19630
|
+
importer,
|
19631
|
+
options,
|
19632
|
+
void 0,
|
19633
|
+
void 0
|
19634
|
+
)?.id : tryFsResolve(path$d.join(pkg.dir, browserMappedPath), options)) {
|
19635
|
+
debug$d?.(`[browser mapped] ${colors$1.cyan(id)} -> ${colors$1.dim(res)}`);
|
19636
|
+
let result = { id: res };
|
19637
|
+
if (options.idOnly) {
|
19638
|
+
return result;
|
19639
|
+
}
|
19640
|
+
if (!options.scan && options.isBuild) {
|
19641
|
+
const resPkg = findNearestPackageData(
|
19642
|
+
path$d.dirname(res),
|
19643
|
+
options.packageCache
|
19644
|
+
);
|
19645
|
+
if (resPkg) {
|
19646
|
+
result = {
|
19647
|
+
id: res,
|
19648
|
+
moduleSideEffects: resPkg.hasSideEffects(res)
|
19649
|
+
};
|
19592
19650
|
}
|
19593
19651
|
}
|
19652
|
+
return externalize ? { ...result, external: true } : result;
|
19594
19653
|
}
|
19654
|
+
} else if (browserMappedPath === false) {
|
19655
|
+
return browserExternalId;
|
19595
19656
|
}
|
19596
|
-
} catch (err) {
|
19597
|
-
config.logger.error(err);
|
19598
19657
|
}
|
19599
19658
|
}
|
19600
|
-
|
19601
|
-
const
|
19602
|
-
|
19603
|
-
|
19604
|
-
|
19605
|
-
|
19606
|
-
|
19607
|
-
|
19608
|
-
|
19609
|
-
|
19610
|
-
|
19611
|
-
|
19612
|
-
|
19613
|
-
|
19614
|
-
}
|
19615
|
-
cb(er);
|
19616
|
-
});
|
19617
|
-
});
|
19618
|
-
|
19619
|
-
var index$1 = {
|
19620
|
-
__proto__: null,
|
19621
|
-
addManuallyIncludedOptimizeDeps: addManuallyIncludedOptimizeDeps,
|
19622
|
-
addOptimizedDepInfo: addOptimizedDepInfo,
|
19623
|
-
cleanupDepsCacheStaleDirs: cleanupDepsCacheStaleDirs,
|
19624
|
-
createIsOptimizedDepFile: createIsOptimizedDepFile,
|
19625
|
-
createIsOptimizedDepUrl: createIsOptimizedDepUrl,
|
19626
|
-
depsFromOptimizedDepInfo: depsFromOptimizedDepInfo,
|
19627
|
-
depsLogString: depsLogString,
|
19628
|
-
discoverProjectDependencies: discoverProjectDependencies,
|
19629
|
-
extractExportsData: extractExportsData,
|
19630
|
-
getDepsCacheDir: getDepsCacheDir,
|
19631
|
-
getOptimizedDepPath: getOptimizedDepPath,
|
19632
|
-
initDepsOptimizerMetadata: initDepsOptimizerMetadata,
|
19633
|
-
isDepOptimizationDisabled: isDepOptimizationDisabled,
|
19634
|
-
loadCachedDepOptimizationMetadata: loadCachedDepOptimizationMetadata,
|
19635
|
-
optimizeDeps: optimizeDeps,
|
19636
|
-
optimizeExplicitEnvironmentDeps: optimizeExplicitEnvironmentDeps,
|
19637
|
-
optimizedDepInfoFromFile: optimizedDepInfoFromFile,
|
19638
|
-
optimizedDepInfoFromId: optimizedDepInfoFromId,
|
19639
|
-
optimizedDepNeedsInterop: optimizedDepNeedsInterop,
|
19640
|
-
runOptimizeDeps: runOptimizeDeps,
|
19641
|
-
toDiscoveredDependencies: toDiscoveredDependencies
|
19642
|
-
};
|
19643
|
-
|
19644
|
-
const jsonExtRE = /\.json(?:$|\?)(?!commonjs-(?:proxy|external))/;
|
19645
|
-
const jsonObjRE = /^\s*\{/;
|
19646
|
-
const jsonLangs = `\\.(?:json|json5)(?:$|\\?)`;
|
19647
|
-
const jsonLangRE = new RegExp(jsonLangs);
|
19648
|
-
const isJSONRequest = (request) => jsonLangRE.test(request);
|
19649
|
-
function jsonPlugin(options, isBuild) {
|
19650
|
-
return {
|
19651
|
-
name: "vite:json",
|
19652
|
-
transform(json, id) {
|
19653
|
-
if (!jsonExtRE.test(id)) return null;
|
19654
|
-
if (SPECIAL_QUERY_RE.test(id)) return null;
|
19655
|
-
json = stripBomTag(json);
|
19656
|
-
try {
|
19657
|
-
if (options.stringify !== false) {
|
19658
|
-
if (options.namedExports && jsonObjRE.test(json)) {
|
19659
|
-
const parsed = JSON.parse(json);
|
19660
|
-
const keys = Object.keys(parsed);
|
19661
|
-
let code = "";
|
19662
|
-
let defaultObjectCode = "{\n";
|
19663
|
-
for (const key of keys) {
|
19664
|
-
if (key === makeLegalIdentifier(key)) {
|
19665
|
-
code += `export const ${key} = ${serializeValue(parsed[key])};
|
19666
|
-
`;
|
19667
|
-
defaultObjectCode += ` ${key},
|
19668
|
-
`;
|
19669
|
-
} else {
|
19670
|
-
defaultObjectCode += ` ${JSON.stringify(key)}: ${serializeValue(parsed[key])},
|
19671
|
-
`;
|
19672
|
-
}
|
19673
|
-
}
|
19674
|
-
defaultObjectCode += "}";
|
19675
|
-
code += `export default ${defaultObjectCode};
|
19676
|
-
`;
|
19677
|
-
return {
|
19678
|
-
code,
|
19679
|
-
map: { mappings: "" }
|
19680
|
-
};
|
19681
|
-
}
|
19682
|
-
if (options.stringify === true || // use 10kB as a threshold for 'auto'
|
19683
|
-
// https://v8.dev/blog/cost-of-javascript-2019#:~:text=A%20good%20rule%20of%20thumb%20is%20to%20apply%20this%20technique%20for%20objects%20of%2010%20kB%20or%20larger
|
19684
|
-
json.length > 10 * 1e3) {
|
19685
|
-
if (isBuild) {
|
19686
|
-
json = JSON.stringify(JSON.parse(json));
|
19687
|
-
}
|
19688
|
-
return {
|
19689
|
-
code: `export default /* #__PURE__ */ JSON.parse(${JSON.stringify(json)})`,
|
19690
|
-
map: { mappings: "" }
|
19691
|
-
};
|
19692
|
-
}
|
19659
|
+
function tryResolveBrowserEntry(dir, data, options) {
|
19660
|
+
const browserEntry = typeof data.browser === "string" ? data.browser : isObject$2(data.browser) && data.browser["."];
|
19661
|
+
if (browserEntry) {
|
19662
|
+
if (!options.isRequire && options.mainFields.includes("module") && typeof data.module === "string" && data.module !== browserEntry) {
|
19663
|
+
const resolvedBrowserEntry = tryFsResolve(
|
19664
|
+
path$d.join(dir, browserEntry),
|
19665
|
+
options
|
19666
|
+
);
|
19667
|
+
if (resolvedBrowserEntry) {
|
19668
|
+
const content = fs__default.readFileSync(resolvedBrowserEntry, "utf-8");
|
19669
|
+
if (hasESMSyntax(content)) {
|
19670
|
+
return browserEntry;
|
19671
|
+
} else {
|
19672
|
+
return data.module;
|
19693
19673
|
}
|
19694
|
-
return {
|
19695
|
-
code: dataToEsm(JSON.parse(json), {
|
19696
|
-
preferConst: true,
|
19697
|
-
namedExports: options.namedExports
|
19698
|
-
}),
|
19699
|
-
map: { mappings: "" }
|
19700
|
-
};
|
19701
|
-
} catch (e) {
|
19702
|
-
const position = extractJsonErrorPosition(e.message, json.length);
|
19703
|
-
const msg = position ? `, invalid JSON syntax found at position ${position}` : `.`;
|
19704
|
-
this.error(`Failed to parse JSON file` + msg, position);
|
19705
19674
|
}
|
19675
|
+
} else {
|
19676
|
+
return browserEntry;
|
19706
19677
|
}
|
19707
|
-
}
|
19678
|
+
}
|
19708
19679
|
}
|
19709
|
-
function
|
19710
|
-
const
|
19711
|
-
|
19712
|
-
|
19680
|
+
function mapWithBrowserField(relativePathInPkgDir, map) {
|
19681
|
+
const normalizedPath = path$d.posix.normalize(relativePathInPkgDir);
|
19682
|
+
for (const key in map) {
|
19683
|
+
const normalizedKey = path$d.posix.normalize(key);
|
19684
|
+
if (normalizedPath === normalizedKey || equalWithoutSuffix(normalizedPath, normalizedKey, ".js") || equalWithoutSuffix(normalizedPath, normalizedKey, "/index.js")) {
|
19685
|
+
return map[key];
|
19686
|
+
}
|
19713
19687
|
}
|
19714
|
-
return valueAsString;
|
19715
19688
|
}
|
19716
|
-
function
|
19717
|
-
|
19718
|
-
|
19689
|
+
function equalWithoutSuffix(path2, key, suffix) {
|
19690
|
+
return key.endsWith(suffix) && key.slice(0, -suffix.length) === path2;
|
19691
|
+
}
|
19692
|
+
function tryResolveRealFile(file, preserveSymlinks) {
|
19693
|
+
const stat = tryStatSync(file);
|
19694
|
+
if (stat?.isFile()) return getRealPath(file, preserveSymlinks);
|
19695
|
+
}
|
19696
|
+
function tryResolveRealFileWithExtensions(filePath, extensions, preserveSymlinks) {
|
19697
|
+
for (const ext of extensions) {
|
19698
|
+
const res = tryResolveRealFile(filePath + ext, preserveSymlinks);
|
19699
|
+
if (res) return res;
|
19719
19700
|
}
|
19720
|
-
|
19721
|
-
|
19701
|
+
}
|
19702
|
+
function tryResolveRealFileOrType(file, preserveSymlinks) {
|
19703
|
+
const fileStat = tryStatSync(file);
|
19704
|
+
if (fileStat?.isFile()) {
|
19705
|
+
return { path: getRealPath(file, preserveSymlinks), type: "file" };
|
19706
|
+
}
|
19707
|
+
if (fileStat?.isDirectory()) {
|
19708
|
+
return { type: "directory" };
|
19709
|
+
}
|
19710
|
+
return;
|
19711
|
+
}
|
19712
|
+
function getRealPath(resolved, preserveSymlinks) {
|
19713
|
+
if (!preserveSymlinks) {
|
19714
|
+
resolved = safeRealpathSync(resolved);
|
19715
|
+
}
|
19716
|
+
return normalizePath$3(resolved);
|
19717
|
+
}
|
19718
|
+
function isDirectory(path2) {
|
19719
|
+
const stat = tryStatSync(path2);
|
19720
|
+
return stat?.isDirectory() ?? false;
|
19722
19721
|
}
|
19723
19722
|
|
19724
19723
|
const debug$c = createDebugger("vite:optimize-deps");
|
19725
19724
|
function optimizedDepsPlugin() {
|
19726
19725
|
return {
|
19727
19726
|
name: "vite:optimized-deps",
|
19727
|
+
applyToEnvironment(environment) {
|
19728
|
+
return !isDepOptimizationDisabled(environment.config.optimizeDeps);
|
19729
|
+
},
|
19728
19730
|
resolveId(id) {
|
19729
19731
|
const environment = this.environment;
|
19730
19732
|
if (environment.depsOptimizer?.isOptimizedDepFile(id)) {
|
@@ -30729,7 +30731,7 @@ function ssrRewriteStacktrace(stack, moduleGraph) {
|
|
30729
30731
|
if (!pos.source) {
|
30730
30732
|
return input;
|
30731
30733
|
}
|
30732
|
-
const trimmedVarName = varName
|
30734
|
+
const trimmedVarName = varName?.trim();
|
30733
30735
|
const sourceFile = path$d.resolve(path$d.dirname(id), pos.source);
|
30734
30736
|
const source = `${sourceFile}:${pos.line}:${pos.column + 1}`;
|
30735
30737
|
if (!trimmedVarName || trimmedVarName === "eval") {
|
@@ -40515,7 +40517,7 @@ function htmlFallbackMiddleware(root, spaFallback) {
|
|
40515
40517
|
req.url = url;
|
40516
40518
|
return next();
|
40517
40519
|
}
|
40518
|
-
} else if (pathname
|
40520
|
+
} else if (pathname.endsWith("/")) {
|
40519
40521
|
const filePath = path$d.join(root, pathname, "index.html");
|
40520
40522
|
if (fs__default.existsSync(filePath)) {
|
40521
40523
|
const newUrl = url + "index.html";
|
@@ -41030,7 +41032,7 @@ function serveStaticMiddleware(server) {
|
|
41030
41032
|
);
|
41031
41033
|
return function viteServeStaticMiddleware(req, res, next) {
|
41032
41034
|
const cleanedUrl = cleanUrl(req.url);
|
41033
|
-
if (cleanedUrl
|
41035
|
+
if (cleanedUrl.endsWith("/") || path$d.extname(cleanedUrl) === ".html" || isInternalRequest(req.url) || // skip url starting with // as these will be interpreted as
|
41034
41036
|
// scheme relative URLs by new URL() and will not be a valid file path
|
41035
41037
|
req.url?.startsWith("//")) {
|
41036
41038
|
return next();
|
@@ -41052,7 +41054,7 @@ function serveStaticMiddleware(server) {
|
|
41052
41054
|
}
|
41053
41055
|
const resolvedPathname = redirectedPathname || pathname;
|
41054
41056
|
let fileUrl = path$d.resolve(dir, removeLeadingSlash(resolvedPathname));
|
41055
|
-
if (resolvedPathname
|
41057
|
+
if (resolvedPathname.endsWith("/") && fileUrl[fileUrl.length - 1] !== "/") {
|
41056
41058
|
fileUrl = withTrailingSlash(fileUrl);
|
41057
41059
|
}
|
41058
41060
|
if (!ensureServingAccess(fileUrl, server, res, next)) {
|
@@ -41701,7 +41703,7 @@ function getScriptInfo(node) {
|
|
41701
41703
|
src = p;
|
41702
41704
|
srcSourceCodeLocation = node.sourceCodeLocation?.attrs["src"];
|
41703
41705
|
}
|
41704
|
-
} else if (p.name === "type" && p.value
|
41706
|
+
} else if (p.name === "type" && p.value === "module") {
|
41705
41707
|
isModule = true;
|
41706
41708
|
} else if (p.name === "async") {
|
41707
41709
|
isAsync = true;
|
@@ -42906,12 +42908,6 @@ function isBareRelative(url) {
|
|
42906
42908
|
}
|
42907
42909
|
const processNodeUrl = (url, useSrcSetReplacer, config, htmlPath, originalUrl, server, isClassicScriptLink) => {
|
42908
42910
|
const replacer = (url2) => {
|
42909
|
-
if (server) {
|
42910
|
-
const mod = server.environments.client.moduleGraph.urlToModuleMap.get(url2);
|
42911
|
-
if (mod && mod.lastHMRTimestamp > 0) {
|
42912
|
-
url2 = injectQuery(url2, `t=${mod.lastHMRTimestamp}`);
|
42913
|
-
}
|
42914
|
-
}
|
42915
42911
|
if (url2[0] === "/" && url2[1] !== "/" || // #3230 if some request url (localhost:3000/a/b) return to fallback html, the relative assets
|
42916
42912
|
// path will add `/a/` prefix, it will caused 404.
|
42917
42913
|
//
|
@@ -42923,8 +42919,8 @@ const processNodeUrl = (url, useSrcSetReplacer, config, htmlPath, originalUrl, s
|
|
42923
42919
|
(url2[0] === "." || isBareRelative(url2)) && originalUrl && originalUrl !== "/" && htmlPath === "/index.html") {
|
42924
42920
|
url2 = path$d.posix.join(config.base, url2);
|
42925
42921
|
}
|
42926
|
-
|
42927
|
-
|
42922
|
+
let preTransformUrl;
|
42923
|
+
if (!isClassicScriptLink && shouldPreTransform(url2, config)) {
|
42928
42924
|
if (url2[0] === "/" && url2[1] !== "/") {
|
42929
42925
|
preTransformUrl = url2;
|
42930
42926
|
} else if (url2[0] === "." || isBareRelative(url2)) {
|
@@ -42934,14 +42930,22 @@ const processNodeUrl = (url, useSrcSetReplacer, config, htmlPath, originalUrl, s
|
|
42934
42930
|
url2
|
42935
42931
|
);
|
42936
42932
|
}
|
42937
|
-
|
42938
|
-
|
42939
|
-
|
42940
|
-
|
42941
|
-
|
42942
|
-
|
42943
|
-
|
42933
|
+
}
|
42934
|
+
if (server) {
|
42935
|
+
const mod = server.environments.client.moduleGraph.urlToModuleMap.get(
|
42936
|
+
preTransformUrl || url2
|
42937
|
+
);
|
42938
|
+
if (mod && mod.lastHMRTimestamp > 0) {
|
42939
|
+
url2 = injectQuery(url2, `t=${mod.lastHMRTimestamp}`);
|
42940
|
+
}
|
42941
|
+
}
|
42942
|
+
if (server && preTransformUrl) {
|
42943
|
+
try {
|
42944
|
+
preTransformUrl = decodeURI(preTransformUrl);
|
42945
|
+
} catch {
|
42946
|
+
return url2;
|
42944
42947
|
}
|
42948
|
+
preTransformRequest(server, preTransformUrl, config.decodedBase);
|
42945
42949
|
}
|
42946
42950
|
return url2;
|
42947
42951
|
};
|
@@ -45379,6 +45383,17 @@ const WORKER_FILE_ID = "worker_file";
|
|
45379
45383
|
const workerCache = /* @__PURE__ */ new WeakMap();
|
45380
45384
|
function saveEmitWorkerAsset(config, asset) {
|
45381
45385
|
const workerMap = workerCache.get(config.mainConfig || config);
|
45386
|
+
const duplicateAsset = workerMap.assets.get(asset.fileName);
|
45387
|
+
if (duplicateAsset) {
|
45388
|
+
if (!isSameContent(duplicateAsset.source, asset.source)) {
|
45389
|
+
config.logger.warn(
|
45390
|
+
`
|
45391
|
+
` + colors$1.yellow(
|
45392
|
+
`The emitted file ${JSON.stringify(asset.fileName)} overwrites a previously emitted file of the same name.`
|
45393
|
+
)
|
45394
|
+
);
|
45395
|
+
}
|
45396
|
+
}
|
45382
45397
|
workerMap.assets.set(asset.fileName, asset);
|
45383
45398
|
}
|
45384
45399
|
async function bundleWorkerEntry(config, id) {
|
@@ -45725,13 +45740,15 @@ function isSameContent(a, b) {
|
|
45725
45740
|
|
45726
45741
|
function preAliasPlugin(config) {
|
45727
45742
|
const findPatterns = getAliasPatterns(config.resolve.alias);
|
45728
|
-
const isBuild = config.command === "build";
|
45729
45743
|
return {
|
45730
45744
|
name: "vite:pre-alias",
|
45745
|
+
applyToEnvironment(environment) {
|
45746
|
+
return !isDepOptimizationDisabled(environment.config.optimizeDeps);
|
45747
|
+
},
|
45731
45748
|
async resolveId(id, importer, options) {
|
45732
|
-
const
|
45749
|
+
const environment = this.environment;
|
45733
45750
|
const ssr = environment.config.consumer === "server";
|
45734
|
-
const depsOptimizer = environment.
|
45751
|
+
const depsOptimizer = environment.depsOptimizer;
|
45735
45752
|
if (importer && depsOptimizer && bareImportRE.test(id) && !options.scan && id !== "@vite/client" && id !== "@vite/env") {
|
45736
45753
|
if (findPatterns.find((pattern) => matches(pattern, id))) {
|
45737
45754
|
const optimizedId = await tryOptimizedResolve(
|
@@ -45752,7 +45769,7 @@ function preAliasPlugin(config) {
|
|
45752
45769
|
const optimizeDeps = depsOptimizer.options;
|
45753
45770
|
const resolvedId = cleanUrl(resolved.id);
|
45754
45771
|
const isVirtual = resolvedId === id || resolvedId.includes("\0");
|
45755
|
-
if (!isVirtual && fs__default.existsSync(resolvedId) && !moduleListContains(optimizeDeps.exclude, id) && path$d.isAbsolute(resolvedId) && (isInNodeModules$1(resolvedId) || optimizeDeps.include?.includes(id)) && isOptimizable(resolvedId, optimizeDeps) &&
|
45772
|
+
if (!isVirtual && fs__default.existsSync(resolvedId) && !moduleListContains(optimizeDeps.exclude, id) && path$d.isAbsolute(resolvedId) && (isInNodeModules$1(resolvedId) || optimizeDeps.include?.includes(id)) && isOptimizable(resolvedId, optimizeDeps) && (!ssr || optimizeAliasReplacementForSSR(resolvedId, optimizeDeps))) {
|
45756
45773
|
const optimizedInfo = depsOptimizer.registerMissingImport(
|
45757
45774
|
id,
|
45758
45775
|
resolvedId
|
@@ -46730,13 +46747,16 @@ function workerImportMetaUrlPlugin(config) {
|
|
46730
46747
|
};
|
46731
46748
|
return {
|
46732
46749
|
name: "vite:worker-import-meta-url",
|
46750
|
+
applyToEnvironment(environment) {
|
46751
|
+
return environment.config.consumer === "client";
|
46752
|
+
},
|
46733
46753
|
shouldTransformCachedModule({ code }) {
|
46734
46754
|
if (isBuild && config.build.watch && isIncludeWorkerImportMetaUrl(code)) {
|
46735
46755
|
return true;
|
46736
46756
|
}
|
46737
46757
|
},
|
46738
46758
|
async transform(code, id) {
|
46739
|
-
if (
|
46759
|
+
if (isIncludeWorkerImportMetaUrl(code)) {
|
46740
46760
|
let s;
|
46741
46761
|
const cleanString = stripLiteral(code);
|
46742
46762
|
const workerImportMetaUrlRE = /\bnew\s+(?:Worker|SharedWorker)\s*\(\s*(new\s+URL\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*\))/dg;
|
@@ -46808,9 +46828,11 @@ function assetImportMetaUrlPlugin(config) {
|
|
46808
46828
|
};
|
46809
46829
|
return {
|
46810
46830
|
name: "vite:asset-import-meta-url",
|
46831
|
+
applyToEnvironment(environment) {
|
46832
|
+
return environment.config.consumer === "client";
|
46833
|
+
},
|
46811
46834
|
async transform(code, id) {
|
46812
|
-
|
46813
|
-
if (environment.config.consumer === "client" && id !== preloadHelperId && id !== CLIENT_ENTRY && code.includes("new URL") && code.includes(`import.meta.url`)) {
|
46835
|
+
if (id !== preloadHelperId && id !== CLIENT_ENTRY && code.includes("new URL") && code.includes(`import.meta.url`)) {
|
46814
46836
|
let s;
|
46815
46837
|
const assetImportMetaUrlRE = /\bnew\s+URL\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*(?:,\s*)?\)/dg;
|
46816
46838
|
const cleanString = stripLiteral(code);
|
@@ -46865,7 +46887,7 @@ function assetImportMetaUrlPlugin(config) {
|
|
46865
46887
|
tryIndex: false,
|
46866
46888
|
preferRelative: true
|
46867
46889
|
});
|
46868
|
-
file = await assetResolver(environment, url, id);
|
46890
|
+
file = await assetResolver(this.environment, url, id);
|
46869
46891
|
file ??= url[0] === "/" ? slash$1(path$d.join(publicDir, url)) : slash$1(path$d.resolve(path$d.dirname(id), url));
|
46870
46892
|
}
|
46871
46893
|
let builtUrl;
|
@@ -47251,14 +47273,11 @@ async function resolvePlugins(config, prePlugins, normalPlugins, postPlugins) {
|
|
47251
47273
|
const isWorker = config.isWorker;
|
47252
47274
|
const buildPlugins = isBuild ? await (await Promise.resolve().then(function () { return build$1; })).resolveBuildPlugins(config) : { pre: [], post: [] };
|
47253
47275
|
const { modulePreload } = config.build;
|
47254
|
-
const depOptimizationEnabled = !isBuild && Object.values(config.environments).some(
|
47255
|
-
(environment) => !isDepOptimizationDisabled(environment.optimizeDeps)
|
47256
|
-
);
|
47257
47276
|
return [
|
47258
|
-
|
47277
|
+
!isBuild ? optimizedDepsPlugin() : null,
|
47259
47278
|
isBuild ? metadataPlugin() : null,
|
47260
47279
|
!isWorker ? watchPackageDataPlugin(config.packageCache) : null,
|
47261
|
-
preAliasPlugin(config),
|
47280
|
+
!isBuild ? preAliasPlugin(config) : null,
|
47262
47281
|
alias$1({
|
47263
47282
|
entries: config.resolve.alias,
|
47264
47283
|
customResolver: viteAliasCustomResolver
|
@@ -48076,15 +48095,10 @@ class PluginContainer {
|
|
48076
48095
|
// For backward compatibility, buildStart and watchChange are called only for the client environment
|
48077
48096
|
// buildStart is called per environment for a plugin with the perEnvironmentStartEndDuring dev flag
|
48078
48097
|
async buildStart(_options) {
|
48079
|
-
this.environments.client.pluginContainer.buildStart(
|
48080
|
-
_options
|
48081
|
-
);
|
48098
|
+
return this.environments.client.pluginContainer.buildStart(_options);
|
48082
48099
|
}
|
48083
48100
|
async watchChange(id, change) {
|
48084
|
-
this.environments.client.pluginContainer.watchChange(
|
48085
|
-
id,
|
48086
|
-
change
|
48087
|
-
);
|
48101
|
+
return this.environments.client.pluginContainer.watchChange(id, change);
|
48088
48102
|
}
|
48089
48103
|
async resolveId(rawId, importer, options) {
|
48090
48104
|
return this._getPluginContainer(options).resolveId(rawId, importer, options);
|
@@ -48259,10 +48273,10 @@ function cssPlugin(config) {
|
|
48259
48273
|
}
|
48260
48274
|
},
|
48261
48275
|
async transform(raw, id) {
|
48262
|
-
const { environment } = this;
|
48263
48276
|
if (!isCSSRequest(id) || commonjsProxyRE.test(id) || SPECIAL_QUERY_RE.test(id)) {
|
48264
48277
|
return;
|
48265
48278
|
}
|
48279
|
+
const { environment } = this;
|
48266
48280
|
const resolveUrl = (url, importer) => idResolver(environment, url, importer);
|
48267
48281
|
const urlResolver = async (url, importer) => {
|
48268
48282
|
const decodedUrl = decodeURI(url);
|
@@ -48681,12 +48695,17 @@ function cssPostPlugin(config) {
|
|
48681
48695
|
const injectCode = `var ${style} = document.createElement('style');${style}.textContent = ${cssString};document.head.appendChild(${style});`;
|
48682
48696
|
let injectionPoint;
|
48683
48697
|
const wrapIdx = code.indexOf("System.register");
|
48698
|
+
const singleQuoteUseStrict = `'use strict';`;
|
48699
|
+
const doubleQuoteUseStrict = `"use strict";`;
|
48684
48700
|
if (wrapIdx >= 0) {
|
48685
48701
|
const executeFnStart = code.indexOf("execute:", wrapIdx);
|
48686
48702
|
injectionPoint = code.indexOf("{", executeFnStart) + 1;
|
48703
|
+
} else if (code.includes(singleQuoteUseStrict)) {
|
48704
|
+
injectionPoint = code.indexOf(singleQuoteUseStrict) + singleQuoteUseStrict.length;
|
48705
|
+
} else if (code.includes(doubleQuoteUseStrict)) {
|
48706
|
+
injectionPoint = code.indexOf(doubleQuoteUseStrict) + doubleQuoteUseStrict.length;
|
48687
48707
|
} else {
|
48688
|
-
|
48689
|
-
injectionPoint = code.indexOf(insertMark) + insertMark.length;
|
48708
|
+
throw new Error("Injection point for inlined CSS not found");
|
48690
48709
|
}
|
48691
48710
|
s ||= new MagicString(code);
|
48692
48711
|
s.appendRight(injectionPoint, injectCode);
|
@@ -49211,8 +49230,8 @@ function createCachedImport(imp) {
|
|
49211
49230
|
return cached;
|
49212
49231
|
};
|
49213
49232
|
}
|
49214
|
-
const importPostcssImport = createCachedImport(() => import('./dep-
|
49215
|
-
const importPostcssModules = createCachedImport(() => import('./dep-
|
49233
|
+
const importPostcssImport = createCachedImport(() => import('./dep-dLifoI9c.js').then(function (n) { return n.i; }));
|
49234
|
+
const importPostcssModules = createCachedImport(() => import('./dep-BL6Xg-kE.js').then(function (n) { return n.i; }));
|
49216
49235
|
const importPostcss = createCachedImport(() => import('postcss'));
|
49217
49236
|
const preprocessorWorkerControllerCache = /* @__PURE__ */ new WeakMap();
|
49218
49237
|
let alwaysFakeWorkerWorkerControllerCache;
|
@@ -49232,7 +49251,7 @@ async function formatPostcssSourceMap(rawMap, file) {
|
|
49232
49251
|
const inputFileDir = path$d.dirname(file);
|
49233
49252
|
const sources = rawMap.sources.map((source) => {
|
49234
49253
|
const cleanSource = cleanUrl(decodeURIComponent(source));
|
49235
|
-
if (cleanSource[0] === "<" && cleanSource
|
49254
|
+
if (cleanSource[0] === "<" && cleanSource.endsWith(">")) {
|
49236
49255
|
return `\0${cleanSource}`;
|
49237
49256
|
}
|
49238
49257
|
return normalizePath$3(path$d.resolve(inputFileDir, cleanSource));
|
@@ -50279,7 +50298,7 @@ const importLightningCSS = createCachedImport(() => import('lightningcss'));
|
|
50279
50298
|
async function compileLightningCSS(id, src, environment, urlResolver) {
|
50280
50299
|
const { config } = environment;
|
50281
50300
|
const deps = /* @__PURE__ */ new Set();
|
50282
|
-
const filename = id.replace("\0", NULL_BYTE_PLACEHOLDER);
|
50301
|
+
const filename = removeDirectQuery(id).replace("\0", NULL_BYTE_PLACEHOLDER);
|
50283
50302
|
let res;
|
50284
50303
|
try {
|
50285
50304
|
res = styleAttrRE.test(id) ? (await importLightningCSS()).transformStyleAttribute({
|
@@ -50752,7 +50771,7 @@ function buildImportAnalysisPlugin(config) {
|
|
50752
50771
|
let url = name;
|
50753
50772
|
if (!url) {
|
50754
50773
|
const rawUrl = code.slice(start, end);
|
50755
|
-
if (rawUrl[0] === `"` && rawUrl
|
50774
|
+
if (rawUrl[0] === `"` && rawUrl.endsWith(`"`))
|
50756
50775
|
url = rawUrl.slice(1, -1);
|
50757
50776
|
}
|
50758
50777
|
if (!url) continue;
|
@@ -50813,7 +50832,7 @@ function buildImportAnalysisPlugin(config) {
|
|
50813
50832
|
let url = name;
|
50814
50833
|
if (!url) {
|
50815
50834
|
const rawUrl = code.slice(start, end);
|
50816
|
-
if (rawUrl[0] === `"` && rawUrl
|
50835
|
+
if (rawUrl[0] === `"` && rawUrl.endsWith(`"`))
|
50817
50836
|
url = rawUrl.slice(1, -1);
|
50818
50837
|
}
|
50819
50838
|
const deps = /* @__PURE__ */ new Set();
|
@@ -53444,7 +53463,7 @@ async function preview(inlineConfig = {}) {
|
|
53444
53463
|
`The directory "${clientOutDir}" does not exist. Did you build your project?`
|
53445
53464
|
);
|
53446
53465
|
}
|
53447
|
-
const httpsOptions = await resolveHttpsConfig(config.
|
53466
|
+
const httpsOptions = await resolveHttpsConfig(config.preview.https);
|
53448
53467
|
const app = connect$1();
|
53449
53468
|
const httpServer = await resolveHttpServer(config.preview, app, httpsOptions);
|
53450
53469
|
setClientErrorHandler(httpServer, config.logger);
|
@@ -54177,7 +54196,7 @@ async function resolveConfig(inlineConfig, command, defaultMode = "development",
|
|
54177
54196
|
inlineConfig,
|
54178
54197
|
root: resolvedRoot,
|
54179
54198
|
base,
|
54180
|
-
decodedBase:
|
54199
|
+
decodedBase: decodeBase(base),
|
54181
54200
|
rawBase: resolvedBase,
|
54182
54201
|
publicDir: resolvedPublicDir,
|
54183
54202
|
cacheDir,
|
@@ -54376,6 +54395,15 @@ function resolveBaseUrl(base = configDefaults.base, isBuild, logger) {
|
|
54376
54395
|
}
|
54377
54396
|
return base;
|
54378
54397
|
}
|
54398
|
+
function decodeBase(base) {
|
54399
|
+
try {
|
54400
|
+
return decodeURI(base);
|
54401
|
+
} catch {
|
54402
|
+
throw new Error(
|
54403
|
+
'The value passed to "base" option was malformed. It should be a valid URL.'
|
54404
|
+
);
|
54405
|
+
}
|
54406
|
+
}
|
54379
54407
|
function sortUserPlugins(plugins) {
|
54380
54408
|
const prePlugins = [];
|
54381
54409
|
const postPlugins = [];
|