@vizejs/vite-plugin 0.163.0 → 0.165.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 +79 -30
- 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, rewriteViteStaticAssetUrls, scopeViteCssForPipeline, shouldApplyViteDefineInVirtualModule, splitViteIdQuery, toViteBrowserImportPrefix, transformViteCssVarsForPipeline } 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";
|
|
5
5
|
import { CONFIG_FILE_NAMES, defineConfig, loadConfig, resolveConfigExport } from "vize";
|
|
6
6
|
import fs from "node:fs";
|
|
7
7
|
import { glob } from "tinyglobby";
|
|
@@ -200,6 +200,26 @@ const RESOLVED_CSS_MODULE = "\0vize:all-styles.css";
|
|
|
200
200
|
function toVirtualId(realPath, ssr = false) {
|
|
201
201
|
return createViteVirtualId(realPath, ssr);
|
|
202
202
|
}
|
|
203
|
+
function toPluginVisibleVirtualId(realPath, ssr = false, querySuffix = "") {
|
|
204
|
+
const params = new URLSearchParams(querySuffix.startsWith("?") ? querySuffix.slice(1) : "");
|
|
205
|
+
params.delete("vue");
|
|
206
|
+
params.delete("vize");
|
|
207
|
+
params.delete("vize-ssr");
|
|
208
|
+
const rest = params.toString();
|
|
209
|
+
return `${realPath}.ts?vue&${ssr ? "vize-ssr" : "vize"}${rest ? `&${rest}` : ""}`;
|
|
210
|
+
}
|
|
211
|
+
function fromPluginVisibleVirtualId(id) {
|
|
212
|
+
if (id.startsWith("\0")) return null;
|
|
213
|
+
const request = classifyVitePluginRequest(id);
|
|
214
|
+
if (!request.path.endsWith(".vue.ts") || !request.querySuffix) return null;
|
|
215
|
+
const params = new URLSearchParams(request.querySuffix.slice(1));
|
|
216
|
+
if (!params.has("vue") || !params.has("vize") && !params.has("vize-ssr")) return null;
|
|
217
|
+
return classifyVitePluginRequest(request.normalizedFsId ?? id).normalizedVuePath;
|
|
218
|
+
}
|
|
219
|
+
function isPluginVisibleSsrVirtualId(id) {
|
|
220
|
+
const request = classifyVitePluginRequest(id);
|
|
221
|
+
return request.querySuffix ? new URLSearchParams(request.querySuffix.slice(1)).has("vize-ssr") : false;
|
|
222
|
+
}
|
|
203
223
|
function toBrowserImportPrefix(replacement) {
|
|
204
224
|
return toViteBrowserImportPrefix(replacement);
|
|
205
225
|
}
|
|
@@ -224,6 +244,10 @@ function rewriteDynamicTemplateImports(code, aliasRules) {
|
|
|
224
244
|
function rewriteStaticAssetUrls(code, aliasRules) {
|
|
225
245
|
return rewriteViteStaticAssetUrls(code, aliasRules);
|
|
226
246
|
}
|
|
247
|
+
function rewriteImportMetaGlobBase(code, importer, root) {
|
|
248
|
+
if (!code.includes("import.meta.glob")) return code;
|
|
249
|
+
return rewriteViteImportMetaGlobBase(code, importer, root);
|
|
250
|
+
}
|
|
227
251
|
function shouldApplyDefineInVirtualModule(key) {
|
|
228
252
|
return shouldApplyViteDefineInVirtualModule(key);
|
|
229
253
|
}
|
|
@@ -654,7 +678,7 @@ function nativeCssAliasRules(state) {
|
|
|
654
678
|
return state.cssAliasRules.length === 0 ? EMPTY_NATIVE_ALIAS_RULES : state.cssAliasRules.map(toNativeCssAliasRule);
|
|
655
679
|
}
|
|
656
680
|
function isPotentialVizeResolveId(id) {
|
|
657
|
-
return id.startsWith("\0") || id.startsWith("vize:") || id.startsWith("/@fs") || id === "virtual:vize-styles" || id.endsWith(".vue") || id.includes(".vue?") || id.includes("?macro=true") || id.includes("?definePage");
|
|
681
|
+
return id.startsWith("\0") || id.startsWith("vize:") || id.startsWith("/@fs") || id === "virtual:vize-styles" || id.endsWith(".vue") || id.includes(".vue?") || id.includes(".vue.ts?") || id.includes("?macro=true") || id.includes("?definePage");
|
|
658
682
|
}
|
|
659
683
|
function isPotentialVizeImporter(importer) {
|
|
660
684
|
if (importer === void 0) return false;
|
|
@@ -668,17 +692,17 @@ function shouldCompileVueSfcRequest(request) {
|
|
|
668
692
|
if (params.has("raw") || params.has("url") || params.has("worker") || params.has("sharedworker")) return false;
|
|
669
693
|
return params.has("nuxt_component");
|
|
670
694
|
}
|
|
671
|
-
function hasNuxtComponentQuery
|
|
695
|
+
function hasNuxtComponentQuery(request) {
|
|
672
696
|
if (!request.querySuffix) return false;
|
|
673
697
|
return new URLSearchParams(request.querySuffix.slice(1)).has("nuxt_component");
|
|
674
698
|
}
|
|
675
699
|
function cleanVueSfcImporter(importer, request) {
|
|
676
|
-
let cleanImporter = request?.normalizedFsId ?? importer;
|
|
700
|
+
let cleanImporter = request?.normalizedFsId ?? request?.normalizedVuePath ?? importer;
|
|
677
701
|
if (cleanImporter.startsWith("/@id/__x00__")) cleanImporter = cleanImporter.slice(12);
|
|
678
702
|
else if (cleanImporter.startsWith("__x00__")) cleanImporter = cleanImporter.slice(7);
|
|
679
703
|
return cleanImporter.endsWith(".vue.ts") ? cleanImporter.slice(0, -3) : cleanImporter;
|
|
680
704
|
}
|
|
681
|
-
async function resolveAliasedVueImport(ctx, state, id, importer, isSsrRequest, handleNodeModules, querySuffix, preserveQueryAsPath) {
|
|
705
|
+
async function resolveAliasedVueImport(ctx, state, id, importer, isSsrRequest, handleNodeModules, querySuffix, preserveQueryAsPath, isDependencyScan) {
|
|
682
706
|
if (path.isAbsolute(id)) return null;
|
|
683
707
|
const viteImporter = normalizeViteRequireBase(importer) ?? importer;
|
|
684
708
|
const viteResolved = await ctx.resolve(id, viteImporter, { skipSelf: true });
|
|
@@ -695,19 +719,25 @@ async function resolveAliasedVueImport(ctx, state, id, importer, isSsrRequest, h
|
|
|
695
719
|
}
|
|
696
720
|
if (state.cache.has(realPath) || fs.existsSync(realPath)) {
|
|
697
721
|
state.logger.log(`resolveId: resolved via Vite fallback ${id} to ${realPath}`);
|
|
698
|
-
return preserveQueryAsPath ? `${realPath}${querySuffix}` :
|
|
722
|
+
return preserveQueryAsPath ? `${realPath}${querySuffix}` : isDependencyScan ? toVirtualId(realPath, isSsrRequest) : toPluginVisibleVirtualId(realPath, isSsrRequest, querySuffix);
|
|
699
723
|
}
|
|
700
724
|
return null;
|
|
701
725
|
}
|
|
702
726
|
async function resolveIdHook(ctx, state, id, importer, options) {
|
|
703
727
|
if (!isPotentialVizeResolveId(id) && !isPotentialVizeImporter(importer)) return null;
|
|
704
728
|
const isBuild = state.server === null;
|
|
729
|
+
const isDependencyScan = !!options?.scan;
|
|
705
730
|
const importerRequest = importer ? classifyVitePluginRequest(importer) : null;
|
|
706
|
-
const isSsrRequest = !!options?.ssr || (importerRequest?.isVizeSsrVirtual ?? false);
|
|
731
|
+
const isSsrRequest = !!options?.ssr || (importerRequest?.isVizeSsrVirtual ?? false) || (importer ? isPluginVisibleSsrVirtualId(importer) : false);
|
|
707
732
|
const request = classifyVitePluginRequest(id);
|
|
733
|
+
const pluginVisibleVirtualPath = fromPluginVisibleVirtualId(id);
|
|
734
|
+
if (pluginVisibleVirtualPath) {
|
|
735
|
+
if (isDependencyScan) return toVirtualId(pluginVisibleVirtualPath, isSsrRequest);
|
|
736
|
+
return isSsrRequest ? toPluginVisibleVirtualId(pluginVisibleVirtualPath, true, request.querySuffix) : id;
|
|
737
|
+
}
|
|
708
738
|
if (id.startsWith("\0")) {
|
|
709
739
|
if (request.isVizeVirtual) {
|
|
710
|
-
if (isSsrRequest && !request.isVizeSsrVirtual && request.vizeVirtualPath) return
|
|
740
|
+
if (isSsrRequest && !request.isVizeSsrVirtual && request.vizeVirtualPath) return isDependencyScan ? toVirtualId(request.vizeVirtualPath, true) : toPluginVisibleVirtualId(request.vizeVirtualPath, true, request.querySuffix);
|
|
711
741
|
return id;
|
|
712
742
|
}
|
|
713
743
|
if (id.startsWith("\0vize:")) {
|
|
@@ -912,7 +942,7 @@ async function resolveIdHook(ctx, state, id, importer, options) {
|
|
|
912
942
|
}
|
|
913
943
|
if (shouldCompileVueSfcRequest(request)) {
|
|
914
944
|
const handleNodeModules = state.mergedOptions.handleNodeModulesVue ?? true;
|
|
915
|
-
const preserveQueryAsPath = hasNuxtComponentQuery
|
|
945
|
+
const preserveQueryAsPath = hasNuxtComponentQuery(request);
|
|
916
946
|
const vueRequestPath = request.path;
|
|
917
947
|
if (!handleNodeModules && vueRequestPath.includes("node_modules")) {
|
|
918
948
|
state.logger.log(`resolveId: skipping node_modules import ${id}`);
|
|
@@ -921,7 +951,7 @@ async function resolveIdHook(ctx, state, id, importer, options) {
|
|
|
921
951
|
const resolved = resolveVuePath(state, vueRequestPath, importer);
|
|
922
952
|
const fileExists = fs.existsSync(resolved);
|
|
923
953
|
if (!fileExists) {
|
|
924
|
-
const aliased = await resolveAliasedVueImport(ctx, state, id, importer, isSsrRequest, handleNodeModules, request.querySuffix, preserveQueryAsPath);
|
|
954
|
+
const aliased = await resolveAliasedVueImport(ctx, state, id, importer, isSsrRequest, handleNodeModules, request.querySuffix, preserveQueryAsPath, isDependencyScan);
|
|
925
955
|
if (aliased) return aliased;
|
|
926
956
|
}
|
|
927
957
|
const isNodeModulesPath = resolved.includes("node_modules");
|
|
@@ -937,7 +967,7 @@ async function resolveIdHook(ctx, state, id, importer, options) {
|
|
|
937
967
|
state.logger.log(`resolveId: id=${id}, resolved=${resolved}, hasCache=${hasCache}, fileExists=${fileExists}, importer=${importer ?? "none"}`);
|
|
938
968
|
if (hasCache || fileExists) {
|
|
939
969
|
if (preserveQueryAsPath) return `${resolved}${request.querySuffix}`;
|
|
940
|
-
return
|
|
970
|
+
return isDependencyScan ? toVirtualId(resolved, isSsrRequest) : toPluginVisibleVirtualId(resolved, isSsrRequest, request.querySuffix);
|
|
941
971
|
}
|
|
942
972
|
}
|
|
943
973
|
return null;
|
|
@@ -991,9 +1021,16 @@ function findMacroArtifactModule(state, realPath, ssr, kind) {
|
|
|
991
1021
|
}, realPath, compiled);
|
|
992
1022
|
return compiled?.macroArtifacts?.find((artifact) => artifact.kind === kind)?.moduleCode ?? null;
|
|
993
1023
|
}
|
|
994
|
-
function
|
|
995
|
-
if (!request.
|
|
996
|
-
|
|
1024
|
+
function shouldLoadVueSfcRequest(request) {
|
|
1025
|
+
if (!request.isVueSfcPath || request.isVueStyleQuery || request.hasMacroQuery || request.hasDefinePageQuery) return false;
|
|
1026
|
+
if (!request.querySuffix) return true;
|
|
1027
|
+
const params = new URLSearchParams(request.querySuffix.slice(1));
|
|
1028
|
+
if (params.has("raw") || params.has("url") || params.has("worker") || params.has("sharedworker")) return false;
|
|
1029
|
+
return params.has("nuxt_component");
|
|
1030
|
+
}
|
|
1031
|
+
function getLoadableVueSfcPath(request) {
|
|
1032
|
+
if (!shouldLoadVueSfcRequest(request)) return null;
|
|
1033
|
+
return classifyVitePluginRequest(request.normalizedFsId ?? request.path).normalizedVuePath;
|
|
997
1034
|
}
|
|
998
1035
|
function normalizeStyleVirtualId(id) {
|
|
999
1036
|
const withoutPrefix = id.startsWith("\0") ? id.slice(1) : id;
|
|
@@ -1035,10 +1072,10 @@ function loadCompiledSfcModule(state, realPath, isSsr, currentBase, loadOptions)
|
|
|
1035
1072
|
extractCss,
|
|
1036
1073
|
filePath: realPath
|
|
1037
1074
|
});
|
|
1038
|
-
const
|
|
1075
|
+
const normalizedOutput = rewriteImportMetaGlobBase(rewriteStaticAssetUrls(rewriteDynamicTemplateImports(isSsr ? normalizeVueServerRendererImport(generatedOutput) : generatedOutput, state.dynamicImportAliasRules), state.dynamicImportAliasRules), realPath, state.root);
|
|
1039
1076
|
if (!loadOptions?.ssr) state.pendingHmrUpdateTypes.delete(realPath);
|
|
1040
1077
|
return {
|
|
1041
|
-
code:
|
|
1078
|
+
code: normalizedOutput,
|
|
1042
1079
|
map: null
|
|
1043
1080
|
};
|
|
1044
1081
|
}
|
|
@@ -1057,6 +1094,8 @@ function loadDefinePageMetaArtifact(state, realPath, ssr) {
|
|
|
1057
1094
|
}
|
|
1058
1095
|
function loadHook(state, id, loadOptions) {
|
|
1059
1096
|
const request = classifyVitePluginRequest(id);
|
|
1097
|
+
const pluginVisibleVirtualPath = fromPluginVisibleVirtualId(id);
|
|
1098
|
+
const loadableVueSfcPath = getLoadableVueSfcPath(request);
|
|
1060
1099
|
const currentBase = loadOptions?.ssr ? state.serverViteBase : state.clientViteBase;
|
|
1061
1100
|
if (id === "\0vize:all-styles.css") {
|
|
1062
1101
|
let allCss = "";
|
|
@@ -1084,9 +1123,7 @@ function loadHook(state, id, loadOptions) {
|
|
|
1084
1123
|
if (fallbackCompiled?.css) return resolveCssImports(fallbackCompiled.css, realPath, state.cssAliasRules, state.server !== null, currentBase);
|
|
1085
1124
|
return "";
|
|
1086
1125
|
}
|
|
1087
|
-
if (id !== "\0vize:all-styles.css" && !id.startsWith("\0"))
|
|
1088
|
-
if (!request.isVueSfcPath || !hasNuxtComponentQuery(request)) return null;
|
|
1089
|
-
}
|
|
1126
|
+
if (id !== "\0vize:all-styles.css" && !id.startsWith("\0") && !pluginVisibleVirtualPath && !loadableVueSfcPath) return null;
|
|
1090
1127
|
if (id.startsWith("\0") && request.hasDefinePageQuery) {
|
|
1091
1128
|
const realPath = request.strippedVirtualPath ?? "";
|
|
1092
1129
|
if (request.isVueSfcPath) return loadDefinePageArtifact(state, realPath, !!loadOptions?.ssr);
|
|
@@ -1102,19 +1139,16 @@ function loadHook(state, id, loadOptions) {
|
|
|
1102
1139
|
};
|
|
1103
1140
|
}
|
|
1104
1141
|
}
|
|
1105
|
-
if (request.isVizeVirtual) {
|
|
1106
|
-
const realPath = request.vizeVirtualPath ?? "";
|
|
1107
|
-
const isSsr = request.isVizeSsrVirtual || !!loadOptions?.ssr;
|
|
1142
|
+
if (request.isVizeVirtual || pluginVisibleVirtualPath) {
|
|
1143
|
+
const realPath = request.vizeVirtualPath ?? pluginVisibleVirtualPath ?? "";
|
|
1144
|
+
const isSsr = request.isVizeSsrVirtual || isPluginVisibleSsrVirtualId(id) || !!loadOptions?.ssr;
|
|
1108
1145
|
if (!realPath.endsWith(".vue")) {
|
|
1109
1146
|
state.logger.log(`load: skipping non-vue virtual module ${realPath}`);
|
|
1110
1147
|
return null;
|
|
1111
1148
|
}
|
|
1112
1149
|
return loadCompiledSfcModule(state, realPath, isSsr, currentBase, loadOptions);
|
|
1113
1150
|
}
|
|
1114
|
-
if (
|
|
1115
|
-
const realPath = classifyVitePluginRequest(request.normalizedFsId ?? request.path).normalizedVuePath;
|
|
1116
|
-
return loadCompiledSfcModule(state, realPath, !!loadOptions?.ssr, currentBase, loadOptions);
|
|
1117
|
-
}
|
|
1151
|
+
if (loadableVueSfcPath) return loadCompiledSfcModule(state, loadableVueSfcPath, !!loadOptions?.ssr, currentBase, loadOptions);
|
|
1118
1152
|
if (id.startsWith("\0")) {
|
|
1119
1153
|
const afterPrefix = id.startsWith("\0vize:") ? id.slice(6) : id.slice(1);
|
|
1120
1154
|
if (afterPrefix.includes("?commonjs-")) return null;
|
|
@@ -1130,10 +1164,11 @@ function loadHook(state, id, loadOptions) {
|
|
|
1130
1164
|
return null;
|
|
1131
1165
|
}
|
|
1132
1166
|
async function transformHook(state, code, id, options) {
|
|
1133
|
-
|
|
1167
|
+
const pluginVisibleVirtualPath = fromPluginVisibleVirtualId(id);
|
|
1168
|
+
if (!id.startsWith("\0") && !pluginVisibleVirtualPath) return null;
|
|
1134
1169
|
const request = classifyVitePluginRequest(id);
|
|
1135
|
-
if (request.isVizeVirtual || request.isMacroVirtualId) {
|
|
1136
|
-
const realPath = request.isMacroVirtualId ? request.strippedVirtualPath ?? "" : request.vizeVirtualPath ?? "";
|
|
1170
|
+
if (request.isVizeVirtual || request.isMacroVirtualId || pluginVisibleVirtualPath) {
|
|
1171
|
+
const realPath = request.isMacroVirtualId ? request.strippedVirtualPath ?? "" : request.vizeVirtualPath ?? pluginVisibleVirtualPath ?? "";
|
|
1137
1172
|
try {
|
|
1138
1173
|
const result = await transformWithOxc(code, realPath, {
|
|
1139
1174
|
lang: "ts",
|
|
@@ -1313,12 +1348,26 @@ function createStylePostTransformPlugin() {
|
|
|
1313
1348
|
}
|
|
1314
1349
|
};
|
|
1315
1350
|
}
|
|
1351
|
+
function stripQuery(id) {
|
|
1352
|
+
const queryStart = id.search(/[?#]/);
|
|
1353
|
+
return queryStart === -1 ? id : id.slice(0, queryStart);
|
|
1354
|
+
}
|
|
1355
|
+
function isSfcLikeSource(code) {
|
|
1356
|
+
return /^<(?:template|script|style)(?:\s|>|\/)/.test(code.trimStart());
|
|
1357
|
+
}
|
|
1358
|
+
function shouldPostTransformSfcLikeModule(state, id) {
|
|
1359
|
+
const filename = stripQuery(id);
|
|
1360
|
+
if (filename.endsWith(".vue") || filename.endsWith(".vue.ts") || filename.includes("node_modules")) return false;
|
|
1361
|
+
if (filename.endsWith(".setup.ts")) return true;
|
|
1362
|
+
if (state.filter(filename) || state.filter(id)) return true;
|
|
1363
|
+
return /\.(?:md|markdown)$/i.test(filename);
|
|
1364
|
+
}
|
|
1316
1365
|
function createPostTransformPlugin(state) {
|
|
1317
1366
|
return {
|
|
1318
1367
|
name: "vize:post-transform",
|
|
1319
1368
|
enforce: "post",
|
|
1320
1369
|
async transform(code, id, transformOptions) {
|
|
1321
|
-
if (
|
|
1370
|
+
if (shouldPostTransformSfcLikeModule(state, id) && isSfcLikeSource(code)) {
|
|
1322
1371
|
state.logger.log(`post-transform: compiling virtual SFC content from ${id}`);
|
|
1323
1372
|
try {
|
|
1324
1373
|
const isSsr = !!transformOptions?.ssr;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vizejs/vite-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.165.0",
|
|
4
4
|
"description": "High-performance native Vite plugin for Vue SFC compilation powered by Vize",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"compiler",
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@vizejs/native": "0.
|
|
42
|
+
"@vizejs/native": "0.165.0",
|
|
43
43
|
"tinyglobby": "0.2.16",
|
|
44
|
-
"vize": "0.
|
|
44
|
+
"vize": "0.165.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/node": "25.7.0",
|