@vizejs/vite-plugin 0.277.0 → 0.278.0
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/index.mjs +135 -20
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
3
|
import * as native from "@vizejs/native";
|
|
4
|
-
import { applyViteDefineReplacements, chunkVitePrecompileFiles, classifyVitePluginRequest, createViteBareImportBases, createViteBareImportCandidates, createViteVirtualId, detectViteHmrUpdateType, diffVitePrecompileFiles, generateViteHmrCode, hasViteHmrChanges, isViteBareSpecifier, normalizeViteCssModuleFilename, normalizeViteDevMiddlewareUrl, normalizeVitePrecompileBatchSize, normalizeViteRequireBase, normalizeViteResolvedVuePath, resolveViteAliasRequest, resolveViteCssImports, resolveViteRelativeImport, resolveViteVuePath, rewriteViteDynamicTemplateImports, rewriteViteImportMetaGlobBase, rewriteViteStaticAssetUrls, scopeViteCssForPipeline, shouldApplyViteDefineInVirtualModule, splitViteIdQuery, toViteBrowserImportPrefix, transformViteCssVarsForPipeline } from "@vizejs/native";
|
|
4
|
+
import { applyViteDefineReplacements, buildInspectorGraph, chunkVitePrecompileFiles, classifyVitePluginRequest, createViteBareImportBases, createViteBareImportCandidates, createViteVirtualId, detectViteHmrUpdateType, diffVitePrecompileFiles, generateViteHmrCode, hasViteHmrChanges, isViteBareSpecifier, normalizeViteCssModuleFilename, normalizeViteDevMiddlewareUrl, normalizeVitePrecompileBatchSize, normalizeViteRequireBase, normalizeViteResolvedVuePath, resolveViteAliasRequest, resolveViteCssImports, resolveViteRelativeImport, resolveViteVuePath, rewriteViteDynamicTemplateImports, rewriteViteImportMetaGlobBase, rewriteViteStaticAssetUrls, scopeViteCssForPipeline, shouldApplyViteDefineInVirtualModule, splitViteIdQuery, toViteBrowserImportPrefix, transformViteCssVarsForPipeline } from "@vizejs/native";
|
|
5
5
|
import fs from "node:fs";
|
|
6
6
|
import { glob } from "tinyglobby";
|
|
7
7
|
import path from "node:path";
|
|
@@ -261,10 +261,17 @@ function toPluginVisibleVirtualId(realPath, ssr = false, querySuffix = "") {
|
|
|
261
261
|
function fromPluginVisibleVirtualId(id) {
|
|
262
262
|
if (id.startsWith("\0")) return null;
|
|
263
263
|
const request = classifyVitePluginRequest(id);
|
|
264
|
-
if (!request.path
|
|
264
|
+
if (!isPluginVisibleVueVirtualPath(request.path) || !request.querySuffix) return null;
|
|
265
265
|
const params = new URLSearchParams(request.querySuffix.slice(1));
|
|
266
266
|
if (!params.has("vue") || !params.has("vize") && !params.has("vize-ssr")) return null;
|
|
267
|
-
return classifyVitePluginRequest(request.normalizedFsId ?? id).
|
|
267
|
+
return stripPluginVisibleVueVirtualSuffix(classifyVitePluginRequest(request.normalizedFsId ?? id).path);
|
|
268
|
+
}
|
|
269
|
+
function isPluginVisibleVueVirtualPath(path) {
|
|
270
|
+
return path.endsWith(".vue.ts") || path.endsWith(".vue.tsx");
|
|
271
|
+
}
|
|
272
|
+
function stripPluginVisibleVueVirtualSuffix(path) {
|
|
273
|
+
if (path.endsWith(".vue.tsx")) return path.slice(0, -4);
|
|
274
|
+
return path.endsWith(".vue.ts") ? path.slice(0, -3) : path;
|
|
268
275
|
}
|
|
269
276
|
function isPluginVisibleSsrVirtualId(id) {
|
|
270
277
|
const request = classifyVitePluginRequest(id);
|
|
@@ -680,7 +687,7 @@ async function compileAll(state) {
|
|
|
680
687
|
state.cache.delete(file);
|
|
681
688
|
if (state.extractCss) state.collectedCss.delete(file);
|
|
682
689
|
state.precompileMetadata.delete(file);
|
|
683
|
-
precompileFailures.push(`[vize] Failed to read ${file}: ${formatUnknownError$
|
|
690
|
+
precompileFailures.push(`[vize] Failed to read ${file}: ${formatUnknownError$2(e)}`);
|
|
684
691
|
state.logger.error(`Failed to read ${file}:`, e);
|
|
685
692
|
}
|
|
686
693
|
if (fileContents.length === 0) continue;
|
|
@@ -719,7 +726,7 @@ async function compileAll(state) {
|
|
|
719
726
|
throw new Error(`[vize] Pre-compilation failed for ${failedCount} file(s).${details}`);
|
|
720
727
|
}
|
|
721
728
|
}
|
|
722
|
-
function formatUnknownError$
|
|
729
|
+
function formatUnknownError$2(error) {
|
|
723
730
|
return error instanceof Error ? error.message : String(error);
|
|
724
731
|
}
|
|
725
732
|
//#endregion
|
|
@@ -760,6 +767,26 @@ function isProjectSourceImporter(root, importer) {
|
|
|
760
767
|
}
|
|
761
768
|
}
|
|
762
769
|
//#endregion
|
|
770
|
+
//#region src/plugin/resolve-relative-vue.ts
|
|
771
|
+
function cleanVueSfcImporter(importer, request) {
|
|
772
|
+
let cleanImporter = request?.normalizedFsId ?? request?.normalizedVuePath ?? importer;
|
|
773
|
+
if (cleanImporter.startsWith("/@id/__x00__")) cleanImporter = cleanImporter.slice(12);
|
|
774
|
+
else if (cleanImporter.startsWith("__x00__")) cleanImporter = cleanImporter.slice(7);
|
|
775
|
+
return classifyVitePluginRequest(cleanImporter).normalizedVuePath;
|
|
776
|
+
}
|
|
777
|
+
async function resolveRelativeVueSfcImport(ctx, state, id, cleanImporter, isSsrRequest, isDependencyScan, resolveWithVite) {
|
|
778
|
+
if (!id.startsWith("./") && !id.startsWith("../")) return null;
|
|
779
|
+
const { request, querySuffix } = splitViteIdQuery(id);
|
|
780
|
+
if (!request.endsWith(".vue")) return null;
|
|
781
|
+
const resolved = await resolveWithVite(ctx, state, id, cleanImporter, { skipSelf: true });
|
|
782
|
+
if (!resolved) return null;
|
|
783
|
+
const resolvedRequest = classifyVitePluginRequest(resolved.id);
|
|
784
|
+
const resolvedPath = resolvedRequest.normalizedFsId ?? resolvedRequest.normalizedVuePath;
|
|
785
|
+
if (!resolvedPath || !resolvedPath.endsWith(".vue")) return resolved;
|
|
786
|
+
const effectiveQuery = resolvedRequest.querySuffix || querySuffix;
|
|
787
|
+
return isDependencyScan ? toVirtualId(resolvedPath, isSsrRequest) : toPluginVisibleVirtualId(resolvedPath, isSsrRequest, effectiveQuery);
|
|
788
|
+
}
|
|
789
|
+
//#endregion
|
|
763
790
|
//#region src/plugin/resolve.ts
|
|
764
791
|
function resolveVuePath(state, id, importer) {
|
|
765
792
|
return resolveViteVuePath(state.root, id, importer);
|
|
@@ -1093,7 +1120,7 @@ function nativeCssAliasRules(state) {
|
|
|
1093
1120
|
return state.cssAliasRules.length === 0 ? EMPTY_NATIVE_ALIAS_RULES : state.cssAliasRules.map(toNativeCssAliasRule);
|
|
1094
1121
|
}
|
|
1095
1122
|
function isPotentialVizeResolveId(id) {
|
|
1096
|
-
return id.startsWith("\0") || id.startsWith("vize:") || id.startsWith("/@fs") || isProjectVueRuntimeRequest(id) || id === "virtual:vize-styles" || id.endsWith(".vue") || id.includes(".vue?") || id
|
|
1123
|
+
return id.startsWith("\0") || id.startsWith("vize:") || id.startsWith("/@fs") || isProjectVueRuntimeRequest(id) || id === "virtual:vize-styles" || id.endsWith(".vue") || id.includes(".vue?") || /\.vue\.tsx?\?/.test(id) || id.includes("?macro=true") || id.includes("?definePage");
|
|
1097
1124
|
}
|
|
1098
1125
|
function classifyImporterRequest(importer) {
|
|
1099
1126
|
return importer ? classifyVitePluginRequest(importer) : null;
|
|
@@ -1114,12 +1141,6 @@ function hasNuxtComponentQuery(request) {
|
|
|
1114
1141
|
if (!request.querySuffix) return false;
|
|
1115
1142
|
return new URLSearchParams(request.querySuffix.slice(1)).has("nuxt_component");
|
|
1116
1143
|
}
|
|
1117
|
-
function cleanVueSfcImporter(importer, request) {
|
|
1118
|
-
let cleanImporter = request?.normalizedFsId ?? request?.normalizedVuePath ?? importer;
|
|
1119
|
-
if (cleanImporter.startsWith("/@id/__x00__")) cleanImporter = cleanImporter.slice(12);
|
|
1120
|
-
else if (cleanImporter.startsWith("__x00__")) cleanImporter = cleanImporter.slice(7);
|
|
1121
|
-
return cleanImporter.endsWith(".vue.ts") ? cleanImporter.slice(0, -3) : cleanImporter;
|
|
1122
|
-
}
|
|
1123
1144
|
async function resolveAliasedVueImport(ctx, state, id, importer, isSsrRequest, handleNodeModules, querySuffix, preserveQueryAsPath, isDependencyScan) {
|
|
1124
1145
|
if (path.isAbsolute(id)) return null;
|
|
1125
1146
|
const viteResolved = await resolveWithVite(ctx, state, id, normalizeViteRequireBase(importer) ?? importer, { skipSelf: true });
|
|
@@ -1207,6 +1228,8 @@ async function resolveIdHook(ctx, state, id, importer, options) {
|
|
|
1207
1228
|
if (importer && (isVizeVirtualImporter || isMacroImporter || isVueSfcImporter)) {
|
|
1208
1229
|
const cleanImporter = isMacroImporter ? importerRequest?.strippedVirtualPath ?? "" : isVizeVirtualImporter ? importerRequest?.vizeVirtualPath ?? "" : cleanVueSfcImporter(importer, importerRequest);
|
|
1209
1230
|
state.logger.log(`resolveId from virtual: id=${id}, cleanImporter=${cleanImporter}`);
|
|
1231
|
+
const relativeVueResolved = await resolveRelativeVueSfcImport(ctx, state, id, cleanImporter, isSsrRequest, isDependencyScan, resolveWithVite);
|
|
1232
|
+
if (relativeVueResolved) return relativeVueResolved;
|
|
1210
1233
|
if (id.startsWith("#")) try {
|
|
1211
1234
|
return await resolveWithVite(ctx, state, id, cleanImporter, { skipSelf: true });
|
|
1212
1235
|
} catch {
|
|
@@ -1705,13 +1728,13 @@ async function transformHook(state, code, id, options) {
|
|
|
1705
1728
|
} catch (dumpError) {
|
|
1706
1729
|
state.logger.error(`Failed to dump failing virtual module for ${realPath}:`, dumpError);
|
|
1707
1730
|
}
|
|
1708
|
-
const message = [`[vize] Virtual module transform failed for ${realPath}: ${formatUnknownError(e)}`, dumpPath ? `Dumped failing code to ${dumpPath}` : null].filter(Boolean).join("\n");
|
|
1731
|
+
const message = [`[vize] Virtual module transform failed for ${realPath}: ${formatUnknownError$1(e)}`, dumpPath ? `Dumped failing code to ${dumpPath}` : null].filter(Boolean).join("\n");
|
|
1709
1732
|
throw new Error(message);
|
|
1710
1733
|
}
|
|
1711
1734
|
}
|
|
1712
1735
|
return null;
|
|
1713
1736
|
}
|
|
1714
|
-
function formatUnknownError(error) {
|
|
1737
|
+
function formatUnknownError$1(error) {
|
|
1715
1738
|
return error instanceof Error ? error.message : String(error);
|
|
1716
1739
|
}
|
|
1717
1740
|
//#endregion
|
|
@@ -1932,7 +1955,7 @@ function isSfcLikeSource(code) {
|
|
|
1932
1955
|
}
|
|
1933
1956
|
function shouldPostTransformSfcLikeModule(state, id) {
|
|
1934
1957
|
const filename = stripQuery(id);
|
|
1935
|
-
if (filename.endsWith(".vue") || filename.endsWith(".vue.ts") || filename.includes("node_modules")) return false;
|
|
1958
|
+
if (filename.endsWith(".vue") || filename.endsWith(".vue.ts") || filename.endsWith(".vue.tsx") || filename.includes("node_modules")) return false;
|
|
1936
1959
|
if (filename.endsWith(".setup.ts")) return true;
|
|
1937
1960
|
if (state.filter(filename) || state.filter(id)) return true;
|
|
1938
1961
|
return /\.(?:md|markdown)$/i.test(filename);
|
|
@@ -1986,10 +2009,10 @@ function stripBridgePrefix$1(id) {
|
|
|
1986
2009
|
return id;
|
|
1987
2010
|
}
|
|
1988
2011
|
function isUnoCssBridgeModuleId(id) {
|
|
1989
|
-
return /\.vue\.
|
|
2012
|
+
return /\.vue\.tsx?(?:\?|$)/.test(stripBridgePrefix$1(id));
|
|
1990
2013
|
}
|
|
1991
2014
|
function normalizeUnoCssBridgeModuleId(id) {
|
|
1992
|
-
return stripBridgePrefix$1(id).replace(/\.
|
|
2015
|
+
return stripBridgePrefix$1(id).replace(/\.tsx?(?=\?|$)/, "");
|
|
1993
2016
|
}
|
|
1994
2017
|
function appendOriginalVueSourceForUnoCss(code, normalizedId) {
|
|
1995
2018
|
const sourcePath = normalizedId.split("?")[0];
|
|
@@ -2036,10 +2059,10 @@ function stripBridgePrefix(id) {
|
|
|
2036
2059
|
return id;
|
|
2037
2060
|
}
|
|
2038
2061
|
function isQuasarBridgeModuleId(id) {
|
|
2039
|
-
return /\.vue\.
|
|
2062
|
+
return /\.vue\.tsx?(?:[?#]|$)/.test(stripBridgePrefix(id));
|
|
2040
2063
|
}
|
|
2041
2064
|
function normalizeQuasarBridgeModuleId(id) {
|
|
2042
|
-
return stripBridgePrefix(id).replace(/\.vue\.
|
|
2065
|
+
return stripBridgePrefix(id).replace(/\.vue\.tsx?(?=[?#]|$)/, ".vue");
|
|
2043
2066
|
}
|
|
2044
2067
|
function patchQuasarBridge(plugins) {
|
|
2045
2068
|
for (const plugin of plugins) {
|
|
@@ -2069,6 +2092,14 @@ function normalizeCssModuleFilename(filename) {
|
|
|
2069
2092
|
}
|
|
2070
2093
|
//#endregion
|
|
2071
2094
|
//#region src/plugin/dev-middleware.ts
|
|
2095
|
+
const VIZE_INSPECTOR_GRAPH_ENDPOINT = "/__vize/inspector/graph";
|
|
2096
|
+
const INSPECTOR_SCRIPT_PATTERNS = ["**/*.{js,jsx,ts,tsx}"];
|
|
2097
|
+
const INSPECTOR_EXTRA_IGNORE_PATTERNS = ["**/*.d.ts"];
|
|
2098
|
+
const INSPECTOR_FILE_EXTENSION_RE = /\.(?:vue|[jt]sx?)$/;
|
|
2099
|
+
function installDevMiddleware(devServer, state) {
|
|
2100
|
+
installVirtualAssetMiddleware(devServer, state);
|
|
2101
|
+
installInspectorGraphMiddleware(devServer, state);
|
|
2102
|
+
}
|
|
2072
2103
|
function installVirtualAssetMiddleware(devServer, state) {
|
|
2073
2104
|
devServer.middlewares.use((req, _res, next) => {
|
|
2074
2105
|
const rewrite = req.url ? normalizeViteDevMiddlewareUrl(req.url) : null;
|
|
@@ -2079,6 +2110,90 @@ function installVirtualAssetMiddleware(devServer, state) {
|
|
|
2079
2110
|
next();
|
|
2080
2111
|
});
|
|
2081
2112
|
}
|
|
2113
|
+
function installInspectorGraphMiddleware(devServer, state) {
|
|
2114
|
+
devServer.middlewares.use((req, res, next) => {
|
|
2115
|
+
if (!isInspectorGraphRequest(req.url)) {
|
|
2116
|
+
next();
|
|
2117
|
+
return;
|
|
2118
|
+
}
|
|
2119
|
+
handleInspectorGraphRequest(req, res, state);
|
|
2120
|
+
});
|
|
2121
|
+
}
|
|
2122
|
+
async function createInspectorGraphPayload(state) {
|
|
2123
|
+
const files = await collectInspectorSourceFiles(state);
|
|
2124
|
+
return {
|
|
2125
|
+
schema: "vize.inspector.graph",
|
|
2126
|
+
version: 1,
|
|
2127
|
+
root: state.root,
|
|
2128
|
+
fileCount: files.length,
|
|
2129
|
+
graph: buildInspectorGraph(files)
|
|
2130
|
+
};
|
|
2131
|
+
}
|
|
2132
|
+
async function collectInspectorSourceFiles(state) {
|
|
2133
|
+
const paths = await glob(resolveInspectorScanPatterns(state.scanPatterns), {
|
|
2134
|
+
cwd: state.root,
|
|
2135
|
+
absolute: true,
|
|
2136
|
+
ignore: [...state.ignorePatterns, ...INSPECTOR_EXTRA_IGNORE_PATTERNS]
|
|
2137
|
+
});
|
|
2138
|
+
const files = [];
|
|
2139
|
+
for (const filePath of [...new Set(paths)].sort()) {
|
|
2140
|
+
if (!INSPECTOR_FILE_EXTENSION_RE.test(filePath)) continue;
|
|
2141
|
+
const stat = statFile(filePath);
|
|
2142
|
+
if (!stat) continue;
|
|
2143
|
+
if (!stat.isFile()) continue;
|
|
2144
|
+
files.push({
|
|
2145
|
+
path: normalizeInspectorPath(state.root, filePath),
|
|
2146
|
+
source: fs.readFileSync(filePath, "utf-8")
|
|
2147
|
+
});
|
|
2148
|
+
}
|
|
2149
|
+
return files;
|
|
2150
|
+
}
|
|
2151
|
+
function isInspectorGraphRequest(reqUrl) {
|
|
2152
|
+
if (!reqUrl) return false;
|
|
2153
|
+
try {
|
|
2154
|
+
return new URL(reqUrl, "http://localhost").pathname === VIZE_INSPECTOR_GRAPH_ENDPOINT;
|
|
2155
|
+
} catch {
|
|
2156
|
+
return false;
|
|
2157
|
+
}
|
|
2158
|
+
}
|
|
2159
|
+
function resolveInspectorScanPatterns(scanPatterns) {
|
|
2160
|
+
return [...scanPatterns && scanPatterns.length > 0 ? scanPatterns : ["**/*.vue"], ...INSPECTOR_SCRIPT_PATTERNS];
|
|
2161
|
+
}
|
|
2162
|
+
function normalizeInspectorPath(root, filePath) {
|
|
2163
|
+
return path.relative(root, filePath).split(path.sep).join("/");
|
|
2164
|
+
}
|
|
2165
|
+
function statFile(filePath) {
|
|
2166
|
+
try {
|
|
2167
|
+
return fs.statSync(filePath);
|
|
2168
|
+
} catch {
|
|
2169
|
+
return null;
|
|
2170
|
+
}
|
|
2171
|
+
}
|
|
2172
|
+
async function handleInspectorGraphRequest(req, res, state) {
|
|
2173
|
+
if (req.method !== "GET" && req.method !== "HEAD") {
|
|
2174
|
+
sendJson(res, 405, { error: "method_not_allowed" });
|
|
2175
|
+
return;
|
|
2176
|
+
}
|
|
2177
|
+
try {
|
|
2178
|
+
sendJson(res, 200, await createInspectorGraphPayload(state), req.method === "HEAD");
|
|
2179
|
+
} catch (error) {
|
|
2180
|
+
state.logger.error("Failed to build inspector graph:", error);
|
|
2181
|
+
sendJson(res, 500, {
|
|
2182
|
+
error: "inspector_graph_failed",
|
|
2183
|
+
message: formatUnknownError(error)
|
|
2184
|
+
});
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
function sendJson(res, statusCode, payload, headOnly = false) {
|
|
2188
|
+
const body = JSON.stringify(payload);
|
|
2189
|
+
res.statusCode = statusCode;
|
|
2190
|
+
res.setHeader("content-type", "application/json; charset=utf-8");
|
|
2191
|
+
res.setHeader("content-length", Buffer.byteLength(body));
|
|
2192
|
+
res.end(headOnly ? void 0 : body);
|
|
2193
|
+
}
|
|
2194
|
+
function formatUnknownError(error) {
|
|
2195
|
+
return error instanceof Error ? error.message : String(error);
|
|
2196
|
+
}
|
|
2082
2197
|
//#endregion
|
|
2083
2198
|
//#region src/plugin/vue-version.ts
|
|
2084
2199
|
function isLegacyVueVersion(version) {
|
|
@@ -2319,7 +2434,7 @@ function vize(options = {}) {
|
|
|
2319
2434
|
},
|
|
2320
2435
|
configureServer(devServer) {
|
|
2321
2436
|
state.server = devServer;
|
|
2322
|
-
|
|
2437
|
+
installDevMiddleware(devServer, state);
|
|
2323
2438
|
},
|
|
2324
2439
|
async buildStart() {
|
|
2325
2440
|
state.viteResolveCache?.clear();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vizejs/vite-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.278.0",
|
|
4
4
|
"description": "High-performance native Vite plugin for Vue SFC compilation powered by Vize",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"compiler",
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@vizejs/native": "0.
|
|
43
|
+
"@vizejs/native": "0.278.0",
|
|
44
44
|
"tinyglobby": "0.2.16",
|
|
45
|
-
"vize": "0.
|
|
45
|
+
"vize": "0.278.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@types/node": "25.9.2",
|