vite 8.0.4 → 8.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/node/chunks/node.js +304 -259
- package/dist/node/index.d.ts +6 -2
- package/dist/node/index.js +1 -1
- package/package.json +1 -1
package/dist/node/chunks/node.js
CHANGED
|
@@ -1088,11 +1088,11 @@ function getDate() {
|
|
|
1088
1088
|
function init$1(debug) {
|
|
1089
1089
|
debug.inspectOpts = Object.assign({}, inspectOpts);
|
|
1090
1090
|
}
|
|
1091
|
-
var require$1, colors$
|
|
1091
|
+
var require$1, colors$37, inspectOpts, humanize$1, createDebug, node_default;
|
|
1092
1092
|
var init_node = __esmMin((() => {
|
|
1093
1093
|
init_core();
|
|
1094
1094
|
require$1 = createRequire(import.meta.url);
|
|
1095
|
-
colors$
|
|
1095
|
+
colors$37 = process.stderr.getColorDepth && process.stderr.getColorDepth() > 2 ? [
|
|
1096
1096
|
20,
|
|
1097
1097
|
21,
|
|
1098
1098
|
26,
|
|
@@ -1194,7 +1194,7 @@ var init_node = __esmMin((() => {
|
|
|
1194
1194
|
} catch (_unused) {
|
|
1195
1195
|
humanize$1 = humanize;
|
|
1196
1196
|
}
|
|
1197
|
-
createDebug = setup(useColors(), colors$
|
|
1197
|
+
createDebug = setup(useColors(), colors$37, log, load, save, formatArgs, init$1);
|
|
1198
1198
|
createDebug.inspectOpts = inspectOpts;
|
|
1199
1199
|
createDebug.formatters.o = function(v) {
|
|
1200
1200
|
this.inspectOpts.colors = this.useColors;
|
|
@@ -19932,6 +19932,25 @@ var import_convert_source_map = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commo
|
|
|
19932
19932
|
};
|
|
19933
19933
|
})))(), 1);
|
|
19934
19934
|
const debug$10 = createDebugger("vite:sourcemap", { onlyWhenFocused: true });
|
|
19935
|
+
/**
|
|
19936
|
+
* Given a file path inside node_modules, returns the package root directory.
|
|
19937
|
+
* For scoped packages like `node_modules/@scope/pkg/dist/foo.js`, returns `node_modules/@scope/pkg`.
|
|
19938
|
+
* Returns `undefined` if the file is not inside node_modules.
|
|
19939
|
+
*/
|
|
19940
|
+
function getNodeModulesPackageRoot(filePath) {
|
|
19941
|
+
const normalized = normalizePath(filePath);
|
|
19942
|
+
const nodeModulesIndex = normalized.lastIndexOf("/node_modules/");
|
|
19943
|
+
if (nodeModulesIndex === -1) return void 0;
|
|
19944
|
+
const packageStart = nodeModulesIndex + 14;
|
|
19945
|
+
const rest = normalized.slice(packageStart);
|
|
19946
|
+
const firstSlash = rest.indexOf("/");
|
|
19947
|
+
let packageName;
|
|
19948
|
+
if (rest.startsWith("@")) {
|
|
19949
|
+
const secondSlash = rest.indexOf("/", firstSlash + 1);
|
|
19950
|
+
packageName = secondSlash === -1 ? rest : rest.slice(0, secondSlash);
|
|
19951
|
+
} else packageName = firstSlash === -1 ? rest : rest.slice(0, firstSlash);
|
|
19952
|
+
return normalized.slice(0, packageStart) + packageName;
|
|
19953
|
+
}
|
|
19935
19954
|
const virtualSourceRE = /^(?:dep:|browser-external:|virtual:)|\0/;
|
|
19936
19955
|
async function computeSourceRoute(map, file) {
|
|
19937
19956
|
let sourceRoot;
|
|
@@ -19942,6 +19961,7 @@ async function computeSourceRoute(map, file) {
|
|
|
19942
19961
|
}
|
|
19943
19962
|
async function injectSourcesContent(map, file, logger) {
|
|
19944
19963
|
let sourceRootPromise;
|
|
19964
|
+
const packageRoot = getNodeModulesPackageRoot(file);
|
|
19945
19965
|
const missingSources = [];
|
|
19946
19966
|
const sourcesContent = map.sourcesContent || [];
|
|
19947
19967
|
const sourcesContentPromises = [];
|
|
@@ -19952,6 +19972,14 @@ async function injectSourcesContent(map, file, logger) {
|
|
|
19952
19972
|
const sourceRoot = await sourceRootPromise;
|
|
19953
19973
|
let resolvedSourcePath = cleanUrl(decodeURI(sourcePath));
|
|
19954
19974
|
if (sourceRoot) resolvedSourcePath = path.resolve(sourceRoot, resolvedSourcePath);
|
|
19975
|
+
if (packageRoot) {
|
|
19976
|
+
const resolvedSourcePathNormalized = normalizePath(path.resolve(resolvedSourcePath));
|
|
19977
|
+
if (!isParentDirectory(packageRoot, resolvedSourcePathNormalized)) {
|
|
19978
|
+
sourcesContent[index] = null;
|
|
19979
|
+
logger.warnOnce(import_picocolors.default.yellow(`Sourcemap for ${JSON.stringify(file)} points to a source file outside its package: ${JSON.stringify(resolvedSourcePathNormalized)}`));
|
|
19980
|
+
return;
|
|
19981
|
+
}
|
|
19982
|
+
}
|
|
19955
19983
|
sourcesContent[index] = await fsp.readFile(resolvedSourcePath, "utf-8").catch(() => {
|
|
19956
19984
|
missingSources.push(resolvedSourcePath);
|
|
19957
19985
|
return null;
|
|
@@ -19991,16 +20019,22 @@ function applySourcemapIgnoreList(map, sourcemapPath, sourcemapIgnoreList, logge
|
|
|
19991
20019
|
}
|
|
19992
20020
|
}
|
|
19993
20021
|
}
|
|
19994
|
-
function extractSourcemapFromFile(code, filePath) {
|
|
19995
|
-
const map = (import_convert_source_map.fromSource(code) || import_convert_source_map.fromMapFileSource(code, createConvertSourceMapReadMap(filePath)))?.toObject();
|
|
20022
|
+
function extractSourcemapFromFile(code, filePath, logger) {
|
|
20023
|
+
const map = (import_convert_source_map.fromSource(code) || import_convert_source_map.fromMapFileSource(code, createConvertSourceMapReadMap(filePath, logger)))?.toObject();
|
|
19996
20024
|
if (map) return {
|
|
19997
20025
|
code: code.replace(import_convert_source_map.default.mapFileCommentRegex, blankReplacer),
|
|
19998
20026
|
map
|
|
19999
20027
|
};
|
|
20000
20028
|
}
|
|
20001
|
-
function createConvertSourceMapReadMap(originalFileName) {
|
|
20029
|
+
function createConvertSourceMapReadMap(originalFileName, logger) {
|
|
20030
|
+
const packageRoot = getNodeModulesPackageRoot(originalFileName);
|
|
20002
20031
|
return (filename) => {
|
|
20003
|
-
|
|
20032
|
+
const resolvedPath = path.resolve(path.dirname(originalFileName), filename);
|
|
20033
|
+
if (packageRoot && !isParentDirectory(packageRoot, normalizePath(resolvedPath))) {
|
|
20034
|
+
logger.warnOnce(import_picocolors.default.yellow(`Sourcemap in "${originalFileName}" references a map file outside its package: "${filename}"`));
|
|
20035
|
+
return "{}";
|
|
20036
|
+
}
|
|
20037
|
+
return fs.readFileSync(resolvedPath, "utf-8");
|
|
20004
20038
|
};
|
|
20005
20039
|
}
|
|
20006
20040
|
//#endregion
|
|
@@ -24069,15 +24103,239 @@ function renderRestrictedErrorHTML(msg) {
|
|
|
24069
24103
|
`;
|
|
24070
24104
|
}
|
|
24071
24105
|
//#endregion
|
|
24072
|
-
//#region src/node/server/
|
|
24106
|
+
//#region src/node/server/send.ts
|
|
24073
24107
|
var import_etag = /* @__PURE__ */ __toESM(require_etag(), 1);
|
|
24108
|
+
const debug$8 = createDebugger("vite:send", { onlyWhenFocused: true });
|
|
24109
|
+
const alias = {
|
|
24110
|
+
js: "text/javascript",
|
|
24111
|
+
css: "text/css",
|
|
24112
|
+
html: "text/html",
|
|
24113
|
+
json: "application/json"
|
|
24114
|
+
};
|
|
24115
|
+
function send(req, res, content, type, options) {
|
|
24116
|
+
const { etag = (0, import_etag.default)(content, { weak: true }), cacheControl = "no-cache", headers, map } = options;
|
|
24117
|
+
if (res.writableEnded) return;
|
|
24118
|
+
if (req.headers["if-none-match"] === etag) {
|
|
24119
|
+
res.statusCode = 304;
|
|
24120
|
+
res.end();
|
|
24121
|
+
return;
|
|
24122
|
+
}
|
|
24123
|
+
res.setHeader("Content-Type", alias[type] || type);
|
|
24124
|
+
res.setHeader("Cache-Control", cacheControl);
|
|
24125
|
+
res.setHeader("Etag", etag);
|
|
24126
|
+
if (headers) for (const name in headers) res.setHeader(name, headers[name]);
|
|
24127
|
+
if (map && "version" in map && map.mappings) {
|
|
24128
|
+
if (type === "js" || type === "css") content = getCodeWithSourcemap(type, content.toString(), map);
|
|
24129
|
+
} else if (type === "js" && (!map || map.mappings !== "")) {
|
|
24130
|
+
const code = content.toString();
|
|
24131
|
+
if (import_convert_source_map.default.mapFileCommentRegex.test(code)) debug$8?.(`Skipped injecting fallback sourcemap for ${req.url}`);
|
|
24132
|
+
else {
|
|
24133
|
+
const urlWithoutTimestamp = removeTimestampQuery(req.url);
|
|
24134
|
+
content = getCodeWithSourcemap(type, code, new MagicString(code).generateMap({
|
|
24135
|
+
source: path.basename(urlWithoutTimestamp),
|
|
24136
|
+
hires: "boundary",
|
|
24137
|
+
includeContent: true
|
|
24138
|
+
}));
|
|
24139
|
+
}
|
|
24140
|
+
}
|
|
24141
|
+
res.statusCode = 200;
|
|
24142
|
+
if (req.method === "HEAD") res.end();
|
|
24143
|
+
else res.end(content);
|
|
24144
|
+
}
|
|
24145
|
+
//#endregion
|
|
24146
|
+
//#region src/node/server/middlewares/transform.ts
|
|
24147
|
+
const debugCache$1 = createDebugger("vite:cache");
|
|
24148
|
+
const knownIgnoreList = new Set(["/", "/favicon.ico"]);
|
|
24149
|
+
const documentFetchDests = new Set([
|
|
24150
|
+
"document",
|
|
24151
|
+
"iframe",
|
|
24152
|
+
"frame",
|
|
24153
|
+
"fencedframe"
|
|
24154
|
+
]);
|
|
24155
|
+
function isDocumentFetchDest(req) {
|
|
24156
|
+
const fetchDest = req.headers["sec-fetch-dest"];
|
|
24157
|
+
return fetchDest !== void 0 && documentFetchDests.has(fetchDest);
|
|
24158
|
+
}
|
|
24159
|
+
const urlRE = /[?&]url\b/;
|
|
24160
|
+
const rawRE = /[?&]raw\b/;
|
|
24161
|
+
const inlineRE$1 = /[?&]inline\b/;
|
|
24162
|
+
const svgRE = /\.svg\b/;
|
|
24163
|
+
function isServerAccessDeniedForTransform(config, id) {
|
|
24164
|
+
if (rawRE.test(id) || urlRE.test(id) || inlineRE$1.test(id) || svgRE.test(id)) return checkLoadingAccess(config, cleanUrl(id)) !== "allowed" || checkLoadingAccess(config, id) !== "allowed";
|
|
24165
|
+
return false;
|
|
24166
|
+
}
|
|
24167
|
+
/**
|
|
24168
|
+
* A middleware that short-circuits the middleware chain to serve cached transformed modules
|
|
24169
|
+
*/
|
|
24170
|
+
function cachedTransformMiddleware(server) {
|
|
24171
|
+
return function viteCachedTransformMiddleware(req, res, next) {
|
|
24172
|
+
const environment = server.environments.client;
|
|
24173
|
+
if (isDocumentFetchDest(req)) {
|
|
24174
|
+
res.appendHeader("Vary", "Sec-Fetch-Dest");
|
|
24175
|
+
return next();
|
|
24176
|
+
}
|
|
24177
|
+
const ifNoneMatch = req.headers["if-none-match"];
|
|
24178
|
+
if (ifNoneMatch) {
|
|
24179
|
+
const moduleByEtag = environment.moduleGraph.getModuleByEtag(ifNoneMatch);
|
|
24180
|
+
if (moduleByEtag?.transformResult?.etag === ifNoneMatch && moduleByEtag.url === req.url) {
|
|
24181
|
+
if (!isCSSRequest(req.url)) {
|
|
24182
|
+
debugCache$1?.(`[304] ${prettifyUrl(req.url, server.config.root)}`);
|
|
24183
|
+
res.statusCode = 304;
|
|
24184
|
+
return res.end();
|
|
24185
|
+
}
|
|
24186
|
+
}
|
|
24187
|
+
}
|
|
24188
|
+
next();
|
|
24189
|
+
};
|
|
24190
|
+
}
|
|
24191
|
+
function transformMiddleware(server) {
|
|
24192
|
+
const { root, publicDir } = server.config;
|
|
24193
|
+
const publicDirInRoot = publicDir.startsWith(withTrailingSlash(root));
|
|
24194
|
+
const publicPath = `${publicDir.slice(root.length)}/`;
|
|
24195
|
+
return async function viteTransformMiddleware(req, res, next) {
|
|
24196
|
+
const environment = server.environments.client;
|
|
24197
|
+
if (req.method !== "GET" && req.method !== "HEAD" || knownIgnoreList.has(req.url) || isDocumentFetchDest(req)) return next();
|
|
24198
|
+
let url;
|
|
24199
|
+
try {
|
|
24200
|
+
url = decodeURI(removeTimestampQuery(req.url)).replace(NULL_BYTE_PLACEHOLDER, "\0");
|
|
24201
|
+
} catch (e) {
|
|
24202
|
+
if (e instanceof URIError) {
|
|
24203
|
+
server.config.logger.warn(import_picocolors.default.yellow(`Malformed URI sequence in request URL: ${removeTimestampQuery(req.url)}`));
|
|
24204
|
+
return next();
|
|
24205
|
+
}
|
|
24206
|
+
return next(e);
|
|
24207
|
+
}
|
|
24208
|
+
const withoutQuery = cleanUrl(url);
|
|
24209
|
+
try {
|
|
24210
|
+
if (withoutQuery.endsWith(".map")) {
|
|
24211
|
+
const depsOptimizer = environment.depsOptimizer;
|
|
24212
|
+
if (depsOptimizer?.isOptimizedDepUrl(url)) {
|
|
24213
|
+
const sourcemapPath = url.startsWith(FS_PREFIX) ? fsPathFromId(url) : normalizePath(path.resolve(server.config.root, url.slice(1)));
|
|
24214
|
+
if (!depsOptimizer.isOptimizedDepFile(sourcemapPath)) return next();
|
|
24215
|
+
try {
|
|
24216
|
+
const map = JSON.parse(await fsp.readFile(sourcemapPath, "utf-8"));
|
|
24217
|
+
applySourcemapIgnoreList(map, sourcemapPath, server.config.server.sourcemapIgnoreList, server.config.logger);
|
|
24218
|
+
return send(req, res, JSON.stringify(map), "json", { headers: server.config.server.headers });
|
|
24219
|
+
} catch {
|
|
24220
|
+
const dummySourceMap = {
|
|
24221
|
+
version: 3,
|
|
24222
|
+
file: sourcemapPath.replace(/\.map$/, ""),
|
|
24223
|
+
sources: [],
|
|
24224
|
+
sourcesContent: [],
|
|
24225
|
+
names: [],
|
|
24226
|
+
mappings: ";;;;;;;;;"
|
|
24227
|
+
};
|
|
24228
|
+
return send(req, res, JSON.stringify(dummySourceMap), "json", {
|
|
24229
|
+
cacheControl: "no-cache",
|
|
24230
|
+
headers: server.config.server.headers
|
|
24231
|
+
});
|
|
24232
|
+
}
|
|
24233
|
+
} else {
|
|
24234
|
+
const originalUrl = url.replace(/\.map($|\?)/, "$1");
|
|
24235
|
+
const map = (await environment.moduleGraph.getModuleByUrl(originalUrl))?.transformResult?.map;
|
|
24236
|
+
if (map) return send(req, res, JSON.stringify(map), "json", { headers: server.config.server.headers });
|
|
24237
|
+
else return next();
|
|
24238
|
+
}
|
|
24239
|
+
}
|
|
24240
|
+
if (publicDirInRoot && url.startsWith(publicPath)) warnAboutExplicitPublicPathInUrl(url);
|
|
24241
|
+
if (req.headers["sec-fetch-dest"] === "script" || isJSRequest(url) || isImportRequest(url) || isCSSRequest(url) || isHTMLProxy(url)) {
|
|
24242
|
+
url = removeImportQuery(url);
|
|
24243
|
+
url = unwrapId(url);
|
|
24244
|
+
if (isCSSRequest(url)) {
|
|
24245
|
+
if (req.headers.accept?.includes("text/css") && !isDirectRequest(url)) url = injectQuery(url, "direct");
|
|
24246
|
+
const ifNoneMatch = req.headers["if-none-match"];
|
|
24247
|
+
if (ifNoneMatch && (await environment.moduleGraph.getModuleByUrl(url))?.transformResult?.etag === ifNoneMatch) {
|
|
24248
|
+
debugCache$1?.(`[304] ${prettifyUrl(url, server.config.root)}`);
|
|
24249
|
+
res.statusCode = 304;
|
|
24250
|
+
return res.end();
|
|
24251
|
+
}
|
|
24252
|
+
}
|
|
24253
|
+
const result = await environment.transformRequest(url);
|
|
24254
|
+
if (result) {
|
|
24255
|
+
const depsOptimizer = environment.depsOptimizer;
|
|
24256
|
+
const type = isDirectCSSRequest(url) ? "css" : "js";
|
|
24257
|
+
const isDep = DEP_VERSION_RE.test(url) || depsOptimizer?.isOptimizedDepUrl(url);
|
|
24258
|
+
return send(req, res, result.code, type, {
|
|
24259
|
+
etag: result.etag,
|
|
24260
|
+
cacheControl: isDep ? "max-age=31536000,immutable" : "no-cache",
|
|
24261
|
+
headers: server.config.server.headers,
|
|
24262
|
+
map: result.map
|
|
24263
|
+
});
|
|
24264
|
+
}
|
|
24265
|
+
}
|
|
24266
|
+
} catch (e) {
|
|
24267
|
+
if (e?.code === "ERR_OPTIMIZE_DEPS_PROCESSING_ERROR") {
|
|
24268
|
+
if (!res.writableEnded) {
|
|
24269
|
+
res.statusCode = 504;
|
|
24270
|
+
res.statusMessage = "Optimize Deps Processing Error";
|
|
24271
|
+
res.end();
|
|
24272
|
+
}
|
|
24273
|
+
server.config.logger.error(e.message);
|
|
24274
|
+
return;
|
|
24275
|
+
}
|
|
24276
|
+
if (e?.code === "ERR_OUTDATED_OPTIMIZED_DEP") {
|
|
24277
|
+
if (!res.writableEnded) {
|
|
24278
|
+
res.statusCode = 504;
|
|
24279
|
+
res.statusMessage = "Outdated Optimize Dep";
|
|
24280
|
+
res.end();
|
|
24281
|
+
}
|
|
24282
|
+
return;
|
|
24283
|
+
}
|
|
24284
|
+
if (e?.code === "ERR_CLOSED_SERVER") {
|
|
24285
|
+
if (!res.writableEnded) {
|
|
24286
|
+
res.statusCode = 504;
|
|
24287
|
+
res.statusMessage = "Outdated Request";
|
|
24288
|
+
res.end();
|
|
24289
|
+
}
|
|
24290
|
+
return;
|
|
24291
|
+
}
|
|
24292
|
+
if (e?.code === "ERR_FILE_NOT_FOUND_IN_OPTIMIZED_DEP_DIR") {
|
|
24293
|
+
if (!res.writableEnded) {
|
|
24294
|
+
res.statusCode = 404;
|
|
24295
|
+
res.end();
|
|
24296
|
+
}
|
|
24297
|
+
server.config.logger.warn(import_picocolors.default.yellow(e.message));
|
|
24298
|
+
return;
|
|
24299
|
+
}
|
|
24300
|
+
if (e?.code === "ERR_LOAD_URL") return next();
|
|
24301
|
+
if (e?.code === "ERR_DENIED_ID") {
|
|
24302
|
+
const id = e.id;
|
|
24303
|
+
let servingAccessResult = checkLoadingAccess(server.config, cleanUrl(id));
|
|
24304
|
+
if (servingAccessResult === "allowed") servingAccessResult = checkLoadingAccess(server.config, id);
|
|
24305
|
+
if (servingAccessResult === "denied") {
|
|
24306
|
+
respondWithAccessDenied(id, server, res);
|
|
24307
|
+
return true;
|
|
24308
|
+
}
|
|
24309
|
+
if (servingAccessResult === "fallback") {
|
|
24310
|
+
next();
|
|
24311
|
+
return true;
|
|
24312
|
+
}
|
|
24313
|
+
throw new Error(`Unexpected access result for id ${id}`);
|
|
24314
|
+
}
|
|
24315
|
+
return next(e);
|
|
24316
|
+
}
|
|
24317
|
+
next();
|
|
24318
|
+
};
|
|
24319
|
+
function warnAboutExplicitPublicPathInUrl(url) {
|
|
24320
|
+
let warning;
|
|
24321
|
+
if (isImportRequest(url)) {
|
|
24322
|
+
const rawUrl = removeImportQuery(url);
|
|
24323
|
+
if (urlRE.test(url)) warning = `Assets in the public directory are served at the root path.\nInstead of ${import_picocolors.default.cyan(rawUrl)}, use ${import_picocolors.default.cyan(rawUrl.replace(publicPath, "/"))}.`;
|
|
24324
|
+
else warning = `Assets in public directory cannot be imported from JavaScript.
|
|
24325
|
+
If you intend to import that asset, put the file in the src directory, and use ${import_picocolors.default.cyan(rawUrl.replace(publicPath, "/src/"))} instead of ${import_picocolors.default.cyan(rawUrl)}.\nIf you intend to use the URL of that asset, use ${import_picocolors.default.cyan(injectQuery(rawUrl.replace(publicPath, "/"), "url"))}.`;
|
|
24326
|
+
} else warning = `Files in the public directory are served at the root path.\nInstead of ${import_picocolors.default.cyan(url)}, use ${import_picocolors.default.cyan(url.replace(publicPath, "/"))}.`;
|
|
24327
|
+
server.config.logger.warn(import_picocolors.default.yellow(warning));
|
|
24328
|
+
}
|
|
24329
|
+
}
|
|
24330
|
+
//#endregion
|
|
24331
|
+
//#region src/node/server/transformRequest.ts
|
|
24074
24332
|
const ERR_LOAD_URL = "ERR_LOAD_URL";
|
|
24075
24333
|
const ERR_LOAD_PUBLIC_URL = "ERR_LOAD_PUBLIC_URL";
|
|
24076
24334
|
const ERR_DENIED_ID = "ERR_DENIED_ID";
|
|
24077
24335
|
const debugLoad = createDebugger("vite:load");
|
|
24078
24336
|
const debugTransform = createDebugger("vite:transform");
|
|
24079
|
-
const debugCache
|
|
24080
|
-
function transformRequest(environment, url, options
|
|
24337
|
+
const debugCache = createDebugger("vite:cache");
|
|
24338
|
+
function transformRequest(environment, url, options) {
|
|
24081
24339
|
if (environment._closing && environment.config.dev.recoverable) throwClosedServerError();
|
|
24082
24340
|
const timestamp = monotonicDateNow();
|
|
24083
24341
|
url = removeTimestampQuery(url);
|
|
@@ -24125,15 +24383,15 @@ async function doTransform(environment, url, options, timestamp) {
|
|
|
24125
24383
|
return result;
|
|
24126
24384
|
}
|
|
24127
24385
|
async function getCachedTransformResult(environment, url, module, timestamp) {
|
|
24128
|
-
const prettyUrl = debugCache
|
|
24386
|
+
const prettyUrl = debugCache ? prettifyUrl(url, environment.config.root) : "";
|
|
24129
24387
|
const softInvalidatedTransformResult = await handleModuleSoftInvalidation(environment, module, timestamp);
|
|
24130
24388
|
if (softInvalidatedTransformResult) {
|
|
24131
|
-
debugCache
|
|
24389
|
+
debugCache?.(`[memory-hmr] ${prettyUrl}`);
|
|
24132
24390
|
return softInvalidatedTransformResult;
|
|
24133
24391
|
}
|
|
24134
24392
|
const cached = module.transformResult;
|
|
24135
24393
|
if (cached) {
|
|
24136
|
-
debugCache
|
|
24394
|
+
debugCache?.(`[memory] ${prettyUrl}`);
|
|
24137
24395
|
return cached;
|
|
24138
24396
|
}
|
|
24139
24397
|
}
|
|
@@ -24141,7 +24399,7 @@ async function loadAndTransform(environment, id, url, options, timestamp, mod, r
|
|
|
24141
24399
|
const { config, pluginContainer, logger } = environment;
|
|
24142
24400
|
const prettyUrl = debugLoad || debugTransform ? prettifyUrl(url, config.root) : "";
|
|
24143
24401
|
const moduleGraph = environment.moduleGraph;
|
|
24144
|
-
if (options.
|
|
24402
|
+
if (!options.skipFsCheck && id[0] !== "\0" && isServerAccessDeniedForTransform(config, id)) {
|
|
24145
24403
|
const err = /* @__PURE__ */ new Error(`Denied ID ${id}`);
|
|
24146
24404
|
err.code = ERR_DENIED_ID;
|
|
24147
24405
|
err.id = id;
|
|
@@ -24154,7 +24412,7 @@ async function loadAndTransform(environment, id, url, options, timestamp, mod, r
|
|
|
24154
24412
|
const loadResult = await pluginContainer.load(id);
|
|
24155
24413
|
if (loadResult == null) {
|
|
24156
24414
|
const file = cleanUrl(id);
|
|
24157
|
-
if (
|
|
24415
|
+
if (options.skipFsCheck || isFileLoadingAllowed(environment.getTopLevelConfig(), slash(file))) {
|
|
24158
24416
|
try {
|
|
24159
24417
|
code = await fsp.readFile(file, "utf-8");
|
|
24160
24418
|
debugLoad?.(`${timeFrom(loadStart)} [fs] ${prettyUrl}`);
|
|
@@ -24164,7 +24422,7 @@ async function loadAndTransform(environment, id, url, options, timestamp, mod, r
|
|
|
24164
24422
|
if (code != null && environment.pluginContainer.watcher) ensureWatchedFile(environment.pluginContainer.watcher, file, config.root);
|
|
24165
24423
|
}
|
|
24166
24424
|
if (code) try {
|
|
24167
|
-
const extracted = extractSourcemapFromFile(code, file);
|
|
24425
|
+
const extracted = extractSourcemapFromFile(code, file, logger);
|
|
24168
24426
|
if (extracted) {
|
|
24169
24427
|
code = extracted.code;
|
|
24170
24428
|
map = extracted.map;
|
|
@@ -24368,6 +24626,10 @@ var DevEnvironment = class extends BaseEnvironment {
|
|
|
24368
24626
|
* @internal
|
|
24369
24627
|
*/
|
|
24370
24628
|
_remoteRunnerOptions;
|
|
24629
|
+
/**
|
|
24630
|
+
* @internal
|
|
24631
|
+
*/
|
|
24632
|
+
_skipFsCheck;
|
|
24371
24633
|
get pluginContainer() {
|
|
24372
24634
|
if (!this._pluginContainer) throw new Error(`${this.name} environment.pluginContainer called before initialized`);
|
|
24373
24635
|
return this._pluginContainer;
|
|
@@ -24405,9 +24667,11 @@ var DevEnvironment = class extends BaseEnvironment {
|
|
|
24405
24667
|
this.moduleGraph = new EnvironmentModuleGraph(name, (url) => this.pluginContainer.resolveId(url, void 0));
|
|
24406
24668
|
this._crawlEndFinder = setupOnCrawlEnd();
|
|
24407
24669
|
this._remoteRunnerOptions = context.remoteRunner ?? {};
|
|
24670
|
+
this._skipFsCheck = !!(context.transport && !(isWebSocketServer in context.transport) && context.transport.skipFsCheck);
|
|
24408
24671
|
this.hot = context.transport ? isWebSocketServer in context.transport ? context.transport : normalizeHotChannel(context.transport, context.hot) : normalizeHotChannel({}, context.hot);
|
|
24409
24672
|
this.hot.setInvokeHandler({
|
|
24410
24673
|
fetchModule: (id, importer, options) => {
|
|
24674
|
+
if (context.disableFetchModule) throw new Error("fetchModule is disabled in this environment");
|
|
24411
24675
|
return this.fetchModule(id, importer, options);
|
|
24412
24676
|
},
|
|
24413
24677
|
getBuiltins: async () => {
|
|
@@ -24466,12 +24730,12 @@ var DevEnvironment = class extends BaseEnvironment {
|
|
|
24466
24730
|
async reloadModule(module) {
|
|
24467
24731
|
if (this.config.server.hmr !== false && module.file) updateModules(this, module.file, [module], monotonicDateNow());
|
|
24468
24732
|
}
|
|
24469
|
-
transformRequest(url
|
|
24470
|
-
return transformRequest(this, url,
|
|
24733
|
+
transformRequest(url) {
|
|
24734
|
+
return transformRequest(this, url, { skipFsCheck: this._skipFsCheck });
|
|
24471
24735
|
}
|
|
24472
24736
|
async warmupRequest(url) {
|
|
24473
24737
|
try {
|
|
24474
|
-
await
|
|
24738
|
+
await transformRequest(this, url, { skipFsCheck: true });
|
|
24475
24739
|
} catch (e) {
|
|
24476
24740
|
if (e?.code === "ERR_OUTDATED_OPTIMIZED_DEP" || e?.code === "ERR_CLOSED_SERVER") return;
|
|
24477
24741
|
this.logger.error(buildErrorMessage(e, [`Pre-transform error: ${e.message}`], false), {
|
|
@@ -24564,7 +24828,7 @@ function setupOnCrawlEnd() {
|
|
|
24564
24828
|
}
|
|
24565
24829
|
//#endregion
|
|
24566
24830
|
//#region src/node/server/environments/fullBundleEnvironment.ts
|
|
24567
|
-
const debug$
|
|
24831
|
+
const debug$7 = createDebugger("vite:full-bundle-mode");
|
|
24568
24832
|
var MemoryFiles = class {
|
|
24569
24833
|
files = /* @__PURE__ */ new Map();
|
|
24570
24834
|
get size() {
|
|
@@ -24611,7 +24875,7 @@ var FullBundleDevEnvironment = class extends DevEnvironment {
|
|
|
24611
24875
|
}
|
|
24612
24876
|
async listen(_server) {
|
|
24613
24877
|
this.hot.listen();
|
|
24614
|
-
debug$
|
|
24878
|
+
debug$7?.("INITIAL: setup bundle options");
|
|
24615
24879
|
const rollupOptions = await this.getRolldownOptions();
|
|
24616
24880
|
if (Array.isArray(rollupOptions.output) && rollupOptions.output.length > 1) throw new Error("multiple output options are not supported in dev mode");
|
|
24617
24881
|
const outputOptions = Array.isArray(rollupOptions.output) ? rollupOptions.output[0] : rollupOptions.output;
|
|
@@ -24635,7 +24899,7 @@ var FullBundleDevEnvironment = class extends DevEnvironment {
|
|
|
24635
24899
|
const { updates, changedFiles } = result;
|
|
24636
24900
|
if (changedFiles.length === 0) return;
|
|
24637
24901
|
if (updates.every((update) => update.update.type === "Noop")) {
|
|
24638
|
-
debug$
|
|
24902
|
+
debug$7?.(`ignored file change for ${changedFiles.join(", ")}`);
|
|
24639
24903
|
return;
|
|
24640
24904
|
}
|
|
24641
24905
|
for (const { clientId, update } of updates) {
|
|
@@ -24665,14 +24929,14 @@ var FullBundleDevEnvironment = class extends DevEnvironment {
|
|
|
24665
24929
|
},
|
|
24666
24930
|
watch: { skipWrite: true }
|
|
24667
24931
|
});
|
|
24668
|
-
debug$
|
|
24932
|
+
debug$7?.("INITIAL: setup dev engine");
|
|
24669
24933
|
this.devEngine.run().then(() => {
|
|
24670
|
-
debug$
|
|
24934
|
+
debug$7?.("INITIAL: run done");
|
|
24671
24935
|
}, (e) => {
|
|
24672
|
-
debug$
|
|
24936
|
+
debug$7?.("INITIAL: run error", e);
|
|
24673
24937
|
});
|
|
24674
24938
|
this.waitForInitialBuildFinish().then(() => {
|
|
24675
|
-
debug$
|
|
24939
|
+
debug$7?.("INITIAL: build done");
|
|
24676
24940
|
this.hot.send({
|
|
24677
24941
|
type: "full-reload",
|
|
24678
24942
|
path: "*"
|
|
@@ -24691,10 +24955,10 @@ var FullBundleDevEnvironment = class extends DevEnvironment {
|
|
|
24691
24955
|
(async () => {
|
|
24692
24956
|
const invalidateCalledModules = this.invalidateCalledModules.get(client);
|
|
24693
24957
|
if (invalidateCalledModules?.has(m.path)) {
|
|
24694
|
-
debug$
|
|
24958
|
+
debug$7?.(`INVALIDATE: invalidate received from ${m.path}, but ignored because it was already invalidated`);
|
|
24695
24959
|
return;
|
|
24696
24960
|
}
|
|
24697
|
-
debug$
|
|
24961
|
+
debug$7?.(`INVALIDATE: invalidate received from ${m.path}, re-triggering HMR`);
|
|
24698
24962
|
if (!invalidateCalledModules) this.invalidateCalledModules.set(client, /* @__PURE__ */ new Set([]));
|
|
24699
24963
|
this.invalidateCalledModules.get(client).add(m.path);
|
|
24700
24964
|
let update;
|
|
@@ -24719,7 +24983,7 @@ var FullBundleDevEnvironment = class extends DevEnvironment {
|
|
|
24719
24983
|
this.devEngine.ensureLatestBuildOutput().then(() => {
|
|
24720
24984
|
this.debouncedFullReload();
|
|
24721
24985
|
});
|
|
24722
|
-
debug$
|
|
24986
|
+
debug$7?.(`TRIGGER: access to stale bundle, triggered bundle re-generation`);
|
|
24723
24987
|
}
|
|
24724
24988
|
return shouldTrigger;
|
|
24725
24989
|
}
|
|
@@ -24765,7 +25029,7 @@ var FullBundleDevEnvironment = class extends DevEnvironment {
|
|
|
24765
25029
|
});
|
|
24766
25030
|
return;
|
|
24767
25031
|
}
|
|
24768
|
-
debug$
|
|
25032
|
+
debug$7?.(`handle hmr output for ${shortFile}`, {
|
|
24769
25033
|
...hmrOutput,
|
|
24770
25034
|
code: typeof hmrOutput.code === "string" ? "[code]" : hmrOutput.code
|
|
24771
25035
|
});
|
|
@@ -24832,7 +25096,7 @@ function debounce(time, cb) {
|
|
|
24832
25096
|
}
|
|
24833
25097
|
//#endregion
|
|
24834
25098
|
//#region src/node/server/middlewares/htmlFallback.ts
|
|
24835
|
-
const debug$
|
|
25099
|
+
const debug$6 = createDebugger("vite:html-fallback");
|
|
24836
25100
|
function htmlFallbackMiddleware(root, spaFallback, clientEnvironment) {
|
|
24837
25101
|
const memoryFiles = clientEnvironment instanceof FullBundleDevEnvironment ? clientEnvironment.memoryFiles : void 0;
|
|
24838
25102
|
function checkFileExists(relativePath) {
|
|
@@ -24849,252 +25113,31 @@ function htmlFallbackMiddleware(root, spaFallback, clientEnvironment) {
|
|
|
24849
25113
|
}
|
|
24850
25114
|
if (pathname.endsWith(".html")) {
|
|
24851
25115
|
if (checkFileExists(pathname)) {
|
|
24852
|
-
debug$
|
|
25116
|
+
debug$6?.(`Rewriting ${req.method} ${req.url} to ${url}`);
|
|
24853
25117
|
req.url = url;
|
|
24854
25118
|
return next();
|
|
24855
25119
|
}
|
|
24856
25120
|
} else if (pathname.endsWith("/")) {
|
|
24857
25121
|
if (checkFileExists(joinUrlSegments(pathname, "index.html"))) {
|
|
24858
25122
|
const newUrl = url + "index.html";
|
|
24859
|
-
debug$
|
|
25123
|
+
debug$6?.(`Rewriting ${req.method} ${req.url} to ${newUrl}`);
|
|
24860
25124
|
req.url = newUrl;
|
|
24861
25125
|
return next();
|
|
24862
25126
|
}
|
|
24863
25127
|
} else if (checkFileExists(pathname + ".html")) {
|
|
24864
25128
|
const newUrl = url + ".html";
|
|
24865
|
-
debug$
|
|
25129
|
+
debug$6?.(`Rewriting ${req.method} ${req.url} to ${newUrl}`);
|
|
24866
25130
|
req.url = newUrl;
|
|
24867
25131
|
return next();
|
|
24868
25132
|
}
|
|
24869
25133
|
if (spaFallback) {
|
|
24870
|
-
debug$
|
|
25134
|
+
debug$6?.(`Rewriting ${req.method} ${req.url} to /index.html`);
|
|
24871
25135
|
req.url = "/index.html";
|
|
24872
25136
|
}
|
|
24873
25137
|
next();
|
|
24874
25138
|
};
|
|
24875
25139
|
}
|
|
24876
25140
|
//#endregion
|
|
24877
|
-
//#region src/node/server/send.ts
|
|
24878
|
-
const debug$6 = createDebugger("vite:send", { onlyWhenFocused: true });
|
|
24879
|
-
const alias = {
|
|
24880
|
-
js: "text/javascript",
|
|
24881
|
-
css: "text/css",
|
|
24882
|
-
html: "text/html",
|
|
24883
|
-
json: "application/json"
|
|
24884
|
-
};
|
|
24885
|
-
function send(req, res, content, type, options) {
|
|
24886
|
-
const { etag = (0, import_etag.default)(content, { weak: true }), cacheControl = "no-cache", headers, map } = options;
|
|
24887
|
-
if (res.writableEnded) return;
|
|
24888
|
-
if (req.headers["if-none-match"] === etag) {
|
|
24889
|
-
res.statusCode = 304;
|
|
24890
|
-
res.end();
|
|
24891
|
-
return;
|
|
24892
|
-
}
|
|
24893
|
-
res.setHeader("Content-Type", alias[type] || type);
|
|
24894
|
-
res.setHeader("Cache-Control", cacheControl);
|
|
24895
|
-
res.setHeader("Etag", etag);
|
|
24896
|
-
if (headers) for (const name in headers) res.setHeader(name, headers[name]);
|
|
24897
|
-
if (map && "version" in map && map.mappings) {
|
|
24898
|
-
if (type === "js" || type === "css") content = getCodeWithSourcemap(type, content.toString(), map);
|
|
24899
|
-
} else if (type === "js" && (!map || map.mappings !== "")) {
|
|
24900
|
-
const code = content.toString();
|
|
24901
|
-
if (import_convert_source_map.default.mapFileCommentRegex.test(code)) debug$6?.(`Skipped injecting fallback sourcemap for ${req.url}`);
|
|
24902
|
-
else {
|
|
24903
|
-
const urlWithoutTimestamp = removeTimestampQuery(req.url);
|
|
24904
|
-
content = getCodeWithSourcemap(type, code, new MagicString(code).generateMap({
|
|
24905
|
-
source: path.basename(urlWithoutTimestamp),
|
|
24906
|
-
hires: "boundary",
|
|
24907
|
-
includeContent: true
|
|
24908
|
-
}));
|
|
24909
|
-
}
|
|
24910
|
-
}
|
|
24911
|
-
res.statusCode = 200;
|
|
24912
|
-
if (req.method === "HEAD") res.end();
|
|
24913
|
-
else res.end(content);
|
|
24914
|
-
}
|
|
24915
|
-
//#endregion
|
|
24916
|
-
//#region src/node/server/middlewares/transform.ts
|
|
24917
|
-
const debugCache = createDebugger("vite:cache");
|
|
24918
|
-
const knownIgnoreList = new Set(["/", "/favicon.ico"]);
|
|
24919
|
-
const documentFetchDests = new Set([
|
|
24920
|
-
"document",
|
|
24921
|
-
"iframe",
|
|
24922
|
-
"frame",
|
|
24923
|
-
"fencedframe"
|
|
24924
|
-
]);
|
|
24925
|
-
function isDocumentFetchDest(req) {
|
|
24926
|
-
const fetchDest = req.headers["sec-fetch-dest"];
|
|
24927
|
-
return fetchDest !== void 0 && documentFetchDests.has(fetchDest);
|
|
24928
|
-
}
|
|
24929
|
-
const urlRE = /[?&]url\b/;
|
|
24930
|
-
const rawRE = /[?&]raw\b/;
|
|
24931
|
-
const inlineRE$1 = /[?&]inline\b/;
|
|
24932
|
-
const svgRE = /\.svg\b/;
|
|
24933
|
-
function isServerAccessDeniedForTransform(config, id) {
|
|
24934
|
-
if (rawRE.test(id) || urlRE.test(id) || inlineRE$1.test(id) || svgRE.test(id)) return checkLoadingAccess(config, id) !== "allowed";
|
|
24935
|
-
return false;
|
|
24936
|
-
}
|
|
24937
|
-
/**
|
|
24938
|
-
* A middleware that short-circuits the middleware chain to serve cached transformed modules
|
|
24939
|
-
*/
|
|
24940
|
-
function cachedTransformMiddleware(server) {
|
|
24941
|
-
return function viteCachedTransformMiddleware(req, res, next) {
|
|
24942
|
-
const environment = server.environments.client;
|
|
24943
|
-
if (isDocumentFetchDest(req)) {
|
|
24944
|
-
res.appendHeader("Vary", "Sec-Fetch-Dest");
|
|
24945
|
-
return next();
|
|
24946
|
-
}
|
|
24947
|
-
const ifNoneMatch = req.headers["if-none-match"];
|
|
24948
|
-
if (ifNoneMatch) {
|
|
24949
|
-
const moduleByEtag = environment.moduleGraph.getModuleByEtag(ifNoneMatch);
|
|
24950
|
-
if (moduleByEtag?.transformResult?.etag === ifNoneMatch && moduleByEtag.url === req.url) {
|
|
24951
|
-
if (!isCSSRequest(req.url)) {
|
|
24952
|
-
debugCache?.(`[304] ${prettifyUrl(req.url, server.config.root)}`);
|
|
24953
|
-
res.statusCode = 304;
|
|
24954
|
-
return res.end();
|
|
24955
|
-
}
|
|
24956
|
-
}
|
|
24957
|
-
}
|
|
24958
|
-
next();
|
|
24959
|
-
};
|
|
24960
|
-
}
|
|
24961
|
-
function transformMiddleware(server) {
|
|
24962
|
-
const { root, publicDir } = server.config;
|
|
24963
|
-
const publicDirInRoot = publicDir.startsWith(withTrailingSlash(root));
|
|
24964
|
-
const publicPath = `${publicDir.slice(root.length)}/`;
|
|
24965
|
-
return async function viteTransformMiddleware(req, res, next) {
|
|
24966
|
-
const environment = server.environments.client;
|
|
24967
|
-
if (req.method !== "GET" && req.method !== "HEAD" || knownIgnoreList.has(req.url) || isDocumentFetchDest(req)) return next();
|
|
24968
|
-
let url;
|
|
24969
|
-
try {
|
|
24970
|
-
url = decodeURI(removeTimestampQuery(req.url)).replace(NULL_BYTE_PLACEHOLDER, "\0");
|
|
24971
|
-
} catch (e) {
|
|
24972
|
-
if (e instanceof URIError) {
|
|
24973
|
-
server.config.logger.warn(import_picocolors.default.yellow(`Malformed URI sequence in request URL: ${removeTimestampQuery(req.url)}`));
|
|
24974
|
-
return next();
|
|
24975
|
-
}
|
|
24976
|
-
return next(e);
|
|
24977
|
-
}
|
|
24978
|
-
const withoutQuery = cleanUrl(url);
|
|
24979
|
-
try {
|
|
24980
|
-
if (withoutQuery.endsWith(".map")) if (environment.depsOptimizer?.isOptimizedDepUrl(url)) {
|
|
24981
|
-
const sourcemapPath = url.startsWith(FS_PREFIX) ? fsPathFromId(url) : normalizePath(path.resolve(server.config.root, url.slice(1)));
|
|
24982
|
-
try {
|
|
24983
|
-
const map = JSON.parse(await fsp.readFile(sourcemapPath, "utf-8"));
|
|
24984
|
-
applySourcemapIgnoreList(map, sourcemapPath, server.config.server.sourcemapIgnoreList, server.config.logger);
|
|
24985
|
-
return send(req, res, JSON.stringify(map), "json", { headers: server.config.server.headers });
|
|
24986
|
-
} catch {
|
|
24987
|
-
const dummySourceMap = {
|
|
24988
|
-
version: 3,
|
|
24989
|
-
file: sourcemapPath.replace(/\.map$/, ""),
|
|
24990
|
-
sources: [],
|
|
24991
|
-
sourcesContent: [],
|
|
24992
|
-
names: [],
|
|
24993
|
-
mappings: ";;;;;;;;;"
|
|
24994
|
-
};
|
|
24995
|
-
return send(req, res, JSON.stringify(dummySourceMap), "json", {
|
|
24996
|
-
cacheControl: "no-cache",
|
|
24997
|
-
headers: server.config.server.headers
|
|
24998
|
-
});
|
|
24999
|
-
}
|
|
25000
|
-
} else {
|
|
25001
|
-
const originalUrl = url.replace(/\.map($|\?)/, "$1");
|
|
25002
|
-
const map = (await environment.moduleGraph.getModuleByUrl(originalUrl))?.transformResult?.map;
|
|
25003
|
-
if (map) return send(req, res, JSON.stringify(map), "json", { headers: server.config.server.headers });
|
|
25004
|
-
else return next();
|
|
25005
|
-
}
|
|
25006
|
-
if (publicDirInRoot && url.startsWith(publicPath)) warnAboutExplicitPublicPathInUrl(url);
|
|
25007
|
-
if (req.headers["sec-fetch-dest"] === "script" || isJSRequest(url) || isImportRequest(url) || isCSSRequest(url) || isHTMLProxy(url)) {
|
|
25008
|
-
url = removeImportQuery(url);
|
|
25009
|
-
url = unwrapId(url);
|
|
25010
|
-
if (isCSSRequest(url)) {
|
|
25011
|
-
if (req.headers.accept?.includes("text/css") && !isDirectRequest(url)) url = injectQuery(url, "direct");
|
|
25012
|
-
const ifNoneMatch = req.headers["if-none-match"];
|
|
25013
|
-
if (ifNoneMatch && (await environment.moduleGraph.getModuleByUrl(url))?.transformResult?.etag === ifNoneMatch) {
|
|
25014
|
-
debugCache?.(`[304] ${prettifyUrl(url, server.config.root)}`);
|
|
25015
|
-
res.statusCode = 304;
|
|
25016
|
-
return res.end();
|
|
25017
|
-
}
|
|
25018
|
-
}
|
|
25019
|
-
const result = await environment.transformRequest(url, { allowId(id) {
|
|
25020
|
-
return id[0] === "\0" || !isServerAccessDeniedForTransform(server.config, id);
|
|
25021
|
-
} });
|
|
25022
|
-
if (result) {
|
|
25023
|
-
const depsOptimizer = environment.depsOptimizer;
|
|
25024
|
-
const type = isDirectCSSRequest(url) ? "css" : "js";
|
|
25025
|
-
const isDep = DEP_VERSION_RE.test(url) || depsOptimizer?.isOptimizedDepUrl(url);
|
|
25026
|
-
return send(req, res, result.code, type, {
|
|
25027
|
-
etag: result.etag,
|
|
25028
|
-
cacheControl: isDep ? "max-age=31536000,immutable" : "no-cache",
|
|
25029
|
-
headers: server.config.server.headers,
|
|
25030
|
-
map: result.map
|
|
25031
|
-
});
|
|
25032
|
-
}
|
|
25033
|
-
}
|
|
25034
|
-
} catch (e) {
|
|
25035
|
-
if (e?.code === "ERR_OPTIMIZE_DEPS_PROCESSING_ERROR") {
|
|
25036
|
-
if (!res.writableEnded) {
|
|
25037
|
-
res.statusCode = 504;
|
|
25038
|
-
res.statusMessage = "Optimize Deps Processing Error";
|
|
25039
|
-
res.end();
|
|
25040
|
-
}
|
|
25041
|
-
server.config.logger.error(e.message);
|
|
25042
|
-
return;
|
|
25043
|
-
}
|
|
25044
|
-
if (e?.code === "ERR_OUTDATED_OPTIMIZED_DEP") {
|
|
25045
|
-
if (!res.writableEnded) {
|
|
25046
|
-
res.statusCode = 504;
|
|
25047
|
-
res.statusMessage = "Outdated Optimize Dep";
|
|
25048
|
-
res.end();
|
|
25049
|
-
}
|
|
25050
|
-
return;
|
|
25051
|
-
}
|
|
25052
|
-
if (e?.code === "ERR_CLOSED_SERVER") {
|
|
25053
|
-
if (!res.writableEnded) {
|
|
25054
|
-
res.statusCode = 504;
|
|
25055
|
-
res.statusMessage = "Outdated Request";
|
|
25056
|
-
res.end();
|
|
25057
|
-
}
|
|
25058
|
-
return;
|
|
25059
|
-
}
|
|
25060
|
-
if (e?.code === "ERR_FILE_NOT_FOUND_IN_OPTIMIZED_DEP_DIR") {
|
|
25061
|
-
if (!res.writableEnded) {
|
|
25062
|
-
res.statusCode = 404;
|
|
25063
|
-
res.end();
|
|
25064
|
-
}
|
|
25065
|
-
server.config.logger.warn(import_picocolors.default.yellow(e.message));
|
|
25066
|
-
return;
|
|
25067
|
-
}
|
|
25068
|
-
if (e?.code === "ERR_LOAD_URL") return next();
|
|
25069
|
-
if (e?.code === "ERR_DENIED_ID") {
|
|
25070
|
-
const id = e.id;
|
|
25071
|
-
const servingAccessResult = checkLoadingAccess(server.config, id);
|
|
25072
|
-
if (servingAccessResult === "denied") {
|
|
25073
|
-
respondWithAccessDenied(id, server, res);
|
|
25074
|
-
return true;
|
|
25075
|
-
}
|
|
25076
|
-
if (servingAccessResult === "fallback") {
|
|
25077
|
-
next();
|
|
25078
|
-
return true;
|
|
25079
|
-
}
|
|
25080
|
-
throw new Error(`Unexpected access result for id ${id}`);
|
|
25081
|
-
}
|
|
25082
|
-
return next(e);
|
|
25083
|
-
}
|
|
25084
|
-
next();
|
|
25085
|
-
};
|
|
25086
|
-
function warnAboutExplicitPublicPathInUrl(url) {
|
|
25087
|
-
let warning;
|
|
25088
|
-
if (isImportRequest(url)) {
|
|
25089
|
-
const rawUrl = removeImportQuery(url);
|
|
25090
|
-
if (urlRE.test(url)) warning = `Assets in the public directory are served at the root path.\nInstead of ${import_picocolors.default.cyan(rawUrl)}, use ${import_picocolors.default.cyan(rawUrl.replace(publicPath, "/"))}.`;
|
|
25091
|
-
else warning = `Assets in public directory cannot be imported from JavaScript.
|
|
25092
|
-
If you intend to import that asset, put the file in the src directory, and use ${import_picocolors.default.cyan(rawUrl.replace(publicPath, "/src/"))} instead of ${import_picocolors.default.cyan(rawUrl)}.\nIf you intend to use the URL of that asset, use ${import_picocolors.default.cyan(injectQuery(rawUrl.replace(publicPath, "/"), "url"))}.`;
|
|
25093
|
-
} else warning = `Files in the public directory are served at the root path.\nInstead of ${import_picocolors.default.cyan(url)}, use ${import_picocolors.default.cyan(url.replace(publicPath, "/"))}.`;
|
|
25094
|
-
server.config.logger.warn(import_picocolors.default.yellow(warning));
|
|
25095
|
-
}
|
|
25096
|
-
}
|
|
25097
|
-
//#endregion
|
|
25098
25141
|
//#region src/node/server/middlewares/indexHtml.ts
|
|
25099
25142
|
function createDevHtmlTransformFn(config) {
|
|
25100
25143
|
const [preHooks, normalHooks, postHooks] = resolveHtmlTransforms(config.plugins);
|
|
@@ -26923,6 +26966,7 @@ function createServerHotChannel() {
|
|
|
26923
26966
|
const innerEmitter = new EventEmitter();
|
|
26924
26967
|
const outsideEmitter = new EventEmitter();
|
|
26925
26968
|
return {
|
|
26969
|
+
skipFsCheck: true,
|
|
26926
26970
|
send(payload) {
|
|
26927
26971
|
outsideEmitter.emit("send", payload);
|
|
26928
26972
|
},
|
|
@@ -29583,7 +29627,7 @@ function formatError(payload, environment, sourceMapCache) {
|
|
|
29583
29627
|
const result = environment.moduleGraph.getModuleById(id)?.transformResult;
|
|
29584
29628
|
if (result && !result.map) try {
|
|
29585
29629
|
const filePath = id.split("?")[0];
|
|
29586
|
-
const extracted = extractSourcemapFromFile(result.code, filePath);
|
|
29630
|
+
const extracted = extractSourcemapFromFile(result.code, filePath, environment.config.logger);
|
|
29587
29631
|
sourceMapCache.set(id, extracted?.map);
|
|
29588
29632
|
return extracted?.map;
|
|
29589
29633
|
} catch {
|
|
@@ -33801,7 +33845,8 @@ function defaultCreateClientDevEnvironment(name, config, context) {
|
|
|
33801
33845
|
});
|
|
33802
33846
|
return new DevEnvironment(name, config, {
|
|
33803
33847
|
hot: true,
|
|
33804
|
-
transport: context.ws
|
|
33848
|
+
transport: context.ws,
|
|
33849
|
+
disableFetchModule: true
|
|
33805
33850
|
});
|
|
33806
33851
|
}
|
|
33807
33852
|
function defaultCreateDevEnvironment(name, config) {
|
|
@@ -34722,4 +34767,4 @@ const parseAst$1 = parseAst;
|
|
|
34722
34767
|
const parseAstAsync$1 = parseAstAsync;
|
|
34723
34768
|
const esbuildVersion = "0.25.0";
|
|
34724
34769
|
//#endregion
|
|
34725
|
-
export { depsFromOptimizedDepInfo as $, builderOptionsDefaults as A, searchForWorkspaceRoot as At, resolveBuilderOptions as B, transformWithEsbuild as Bt, resolvePreviewOptions as C,
|
|
34770
|
+
export { depsFromOptimizedDepInfo as $, builderOptionsDefaults as A, searchForWorkspaceRoot as At, resolveBuilderOptions as B, transformWithEsbuild as Bt, resolvePreviewOptions as C, DevEnvironment as Ct, ChunkMetadataMap as D, fetchModule as Dt, BuildEnvironment as E, isFileServingAllowed as Et, injectEnvironmentToHooks as F, createServerModuleRunnerTransport as Ft, toOutputFilePathInHtml as G, mergeConfig as Gt, resolveRolldownOptions as H, createFilter$1 as Ht, onRollupLog as I, buildErrorMessage as It, addManuallyIncludedOptimizeDeps as J, rollupVersion as Jt, toOutputFilePathInJS as K, normalizePath as Kt, resolveBuildEnvironmentOptions as L, loadEnv as Lt, createBuilder as M, perEnvironmentState as Mt, createToImportMetaURLBasedRelativeRuntime as N, ssrTransform as Nt, build as O, formatPostcssSourceMap as Ot, enhanceRollupError as P, createServerModuleRunner as Pt, createIsOptimizedDepUrl as Q, resolveBuildOutputs as R, resolveEnvPrefix as Rt, preview as S, serverConfigDefaults as St, isRunnableDevEnvironment as T, isFileLoadingAllowed as Tt, resolveUserExternal as U, isCSSRequest as Ut, resolveLibFilename as V, perEnvironmentPlugin as Vt, toOutputFilePathInCss as W, mergeAlias as Wt, cleanupDepsCacheStaleDirs as X, addOptimizedDepInfo as Y, withFilter as Yt, createIsOptimizedDepFile as Z, resolveConfig as _, createServer$2 as _t, minifySync as a, initDepsOptimizerMetadata as at, sortUserPlugins as b, resolveServerOptions as bt, parseAstAsync$1 as c, optimizeDeps as ct, isFetchableDevEnvironment as d, optimizedDepInfoFromId as dt, depsLogString as et, defineConfig as f, optimizedDepNeedsInterop as ft, resolveBaseUrl as g, _createServer as gt, loadConfigFromFile as h, createServerHotChannel as ht, minify as i, getOptimizedDepPath as it, clearLine as j, createIdResolver as jt, buildEnvironmentOptionsDefaults as k, preprocessCSS as kt, parseSync as l, optimizeExplicitEnvironmentDeps as lt, isResolvedConfig as m, toDiscoveredDependencies as mt, esbuildVersion as n, extractExportsData as nt, parse as o, isDepOptimizationDisabled as ot, getDefaultEnvironmentOptions as p, runOptimizeDeps as pt, toOutputFilePathWithoutRuntime as q, rolldownVersion as qt, esmExternalRequirePlugin$1 as r, getDepsCacheDir as rt, parseAst$1 as s, loadCachedDepOptimizationMetadata as st, Visitor as t, discoverProjectDependencies as tt, createFetchableDevEnvironment as u, optimizedDepInfoFromFile as ut, resolveDevEnvironmentOptions as v, createServerCloseFn as vt, createRunnableDevEnvironment as w, send as wt, runnerImport as x, restartServerWithUrls as xt, resolveDevToolsConfig as y, resolveForwardConsoleOptions as yt, resolveBuildPlugins as z, transformWithOxc as zt };
|
package/dist/node/index.d.ts
CHANGED
|
@@ -1019,7 +1019,6 @@ interface TransformOptions {
|
|
|
1019
1019
|
*/
|
|
1020
1020
|
ssr?: boolean;
|
|
1021
1021
|
}
|
|
1022
|
-
interface TransformOptionsInternal {}
|
|
1023
1022
|
//#endregion
|
|
1024
1023
|
//#region src/node/server/moduleGraph.d.ts
|
|
1025
1024
|
declare class EnvironmentModuleNode {
|
|
@@ -1184,6 +1183,11 @@ interface HotChannelClient {
|
|
|
1184
1183
|
}
|
|
1185
1184
|
type HotChannelListener<T extends string = string> = (data: InferCustomEventPayload<T>, client: HotChannelClient) => void;
|
|
1186
1185
|
interface HotChannel<Api = any> {
|
|
1186
|
+
/**
|
|
1187
|
+
* When true, the fs access check is skipped in fetchModule.
|
|
1188
|
+
* Set this for transports that is not exposed over the network.
|
|
1189
|
+
*/
|
|
1190
|
+
skipFsCheck?: boolean;
|
|
1187
1191
|
/**
|
|
1188
1192
|
* Broadcast events to all clients
|
|
1189
1193
|
*/
|
|
@@ -1616,7 +1620,7 @@ declare class DevEnvironment extends BaseEnvironment {
|
|
|
1616
1620
|
*/
|
|
1617
1621
|
fetchModule(id: string, importer?: string, options?: FetchFunctionOptions): Promise<moduleRunner_FetchResult>;
|
|
1618
1622
|
reloadModule(module: EnvironmentModuleNode): Promise<void>;
|
|
1619
|
-
transformRequest(url: string
|
|
1623
|
+
transformRequest(url: string): Promise<TransformResult | null>;
|
|
1620
1624
|
warmupRequest(url: string): Promise<void>;
|
|
1621
1625
|
protected invalidateModule(m: {
|
|
1622
1626
|
path: string;
|
package/dist/node/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { F as defaultAllowedOrigins, N as VERSION, _ as DEFAULT_SERVER_CONDITIONS, d as DEFAULT_CLIENT_MAIN_FIELDS, h as DEFAULT_EXTERNAL_CONDITIONS, n as createLogger, u as DEFAULT_CLIENT_CONDITIONS, v as DEFAULT_SERVER_MAIN_FIELDS } from "./chunks/logger.js";
|
|
2
|
-
import { At as searchForWorkspaceRoot, Bt as transformWithEsbuild, Ct as
|
|
2
|
+
import { At as searchForWorkspaceRoot, Bt as transformWithEsbuild, Ct as DevEnvironment, Dt as fetchModule, E as BuildEnvironment, Et as isFileServingAllowed, Ft as createServerModuleRunnerTransport, Gt as mergeConfig, Ht as createFilter, It as buildErrorMessage, Jt as rollupVersion, Kt as normalizePath, Lt as loadEnv, M as createBuilder, Mt as perEnvironmentState, Nt as ssrTransform, O as build, Ot as formatPostcssSourceMap, Pt as createServerModuleRunner, Rt as resolveEnvPrefix, S as preview, T as isRunnableDevEnvironment, Tt as isFileLoadingAllowed, Ut as isCSSRequest, Vt as perEnvironmentPlugin, Wt as mergeAlias, Yt as withFilter, _ as resolveConfig, _t as createServer, a as minifySync, b as sortUserPlugins, c as parseAstAsync, ct as optimizeDeps, d as isFetchableDevEnvironment, f as defineConfig, h as loadConfigFromFile, ht as createServerHotChannel, i as minify, jt as createIdResolver, kt as preprocessCSS, l as parseSync, n as esbuildVersion, o as parse, qt as rolldownVersion, r as esmExternalRequirePlugin, s as parseAst, t as Visitor, u as createFetchableDevEnvironment, w as createRunnableDevEnvironment, wt as send, x as runnerImport, zt as transformWithOxc } from "./chunks/node.js";
|
|
3
3
|
export { BuildEnvironment, DevEnvironment, Visitor, build, buildErrorMessage, createBuilder, createFetchableDevEnvironment, createFilter, createIdResolver, createLogger, createRunnableDevEnvironment, createServer, createServerHotChannel, createServerModuleRunner, createServerModuleRunnerTransport, defaultAllowedOrigins, DEFAULT_CLIENT_CONDITIONS as defaultClientConditions, DEFAULT_CLIENT_MAIN_FIELDS as defaultClientMainFields, DEFAULT_EXTERNAL_CONDITIONS as defaultExternalConditions, DEFAULT_SERVER_CONDITIONS as defaultServerConditions, DEFAULT_SERVER_MAIN_FIELDS as defaultServerMainFields, defineConfig, esbuildVersion, esmExternalRequirePlugin, fetchModule, formatPostcssSourceMap, isCSSRequest, isFetchableDevEnvironment, isFileLoadingAllowed, isFileServingAllowed, isRunnableDevEnvironment, loadConfigFromFile, loadEnv, mergeAlias, mergeConfig, minify, minifySync, ssrTransform as moduleRunnerTransform, normalizePath, optimizeDeps, parse, parseAst, parseAstAsync, parseSync, perEnvironmentPlugin, perEnvironmentState, preprocessCSS, preview, resolveConfig, resolveEnvPrefix, rolldownVersion, rollupVersion, runnerImport, searchForWorkspaceRoot, send, sortUserPlugins, transformWithEsbuild, transformWithOxc, VERSION as version, withFilter };
|