@vizejs/vite-plugin 0.74.0 → 0.76.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.d.mts +12 -1
- package/dist/index.mjs +64 -9
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -499,6 +499,15 @@ interface VizeConfig {
|
|
|
499
499
|
}
|
|
500
500
|
//#endregion
|
|
501
501
|
//#region src/types.d.ts
|
|
502
|
+
interface MacroArtifact {
|
|
503
|
+
kind: string;
|
|
504
|
+
name: string;
|
|
505
|
+
source: string;
|
|
506
|
+
content: string;
|
|
507
|
+
moduleCode?: string;
|
|
508
|
+
start: number;
|
|
509
|
+
end: number;
|
|
510
|
+
}
|
|
502
511
|
interface VizeOptions {
|
|
503
512
|
/**
|
|
504
513
|
* Override the public base used for dev-time asset URLs such as /@fs paths.
|
|
@@ -602,6 +611,8 @@ interface CompiledModule {
|
|
|
602
611
|
templateHash?: string;
|
|
603
612
|
styleHash?: string;
|
|
604
613
|
scriptHash?: string;
|
|
614
|
+
/** Compile-time macro artifacts extracted from the source SFC */
|
|
615
|
+
macroArtifacts?: MacroArtifact[];
|
|
605
616
|
/** Per-block style metadata extracted from the source SFC */
|
|
606
617
|
styles?: StyleBlockInfo[];
|
|
607
618
|
}
|
|
@@ -631,4 +642,4 @@ declare const __internal: {
|
|
|
631
642
|
rewriteStaticAssetUrls: typeof rewriteStaticAssetUrls;
|
|
632
643
|
};
|
|
633
644
|
//#endregion
|
|
634
|
-
export { type CompiledModule, type LoadConfigOptions, type VizeConfig, type VizeOptions, __internal, rewriteStaticAssetUrls as __internal_rewriteStaticAssetUrls, vize as default, vize, defineConfig, loadConfig, vizeConfigStore };
|
|
645
|
+
export { type CompiledModule, type LoadConfigOptions, type MacroArtifact, type VizeConfig, type VizeOptions, __internal, rewriteStaticAssetUrls as __internal_rewriteStaticAssetUrls, vize as default, vize, defineConfig, loadConfig, vizeConfigStore };
|
package/dist/index.mjs
CHANGED
|
@@ -702,6 +702,7 @@ function compileFile(filePath, cache, options, source) {
|
|
|
702
702
|
templateHash: result.templateHash,
|
|
703
703
|
styleHash: result.styleHash,
|
|
704
704
|
scriptHash: result.scriptHash,
|
|
705
|
+
macroArtifacts: result.macroArtifacts ?? [],
|
|
705
706
|
styles
|
|
706
707
|
};
|
|
707
708
|
cache.set(filePath, compiled);
|
|
@@ -730,6 +731,7 @@ function compileBatch(files, cache, options) {
|
|
|
730
731
|
templateHash: fileResult.templateHash,
|
|
731
732
|
styleHash: fileResult.styleHash,
|
|
732
733
|
scriptHash: fileResult.scriptHash,
|
|
734
|
+
macroArtifacts: fileResult.macroArtifacts ?? [],
|
|
733
735
|
styles
|
|
734
736
|
});
|
|
735
737
|
}
|
|
@@ -857,11 +859,22 @@ function resolveVuePath(state, id, importer) {
|
|
|
857
859
|
if (!path.isAbsolute(resolved)) resolved = path.resolve(state.root, resolved);
|
|
858
860
|
return path.normalize(resolved);
|
|
859
861
|
}
|
|
862
|
+
function hasQueryParam$1(id, name) {
|
|
863
|
+
const query = id.split("?")[1];
|
|
864
|
+
return query ? new URLSearchParams(query).has(name) : false;
|
|
865
|
+
}
|
|
866
|
+
function hasMacroQuery$1(id) {
|
|
867
|
+
const query = id.split("?")[1];
|
|
868
|
+
return query ? new URLSearchParams(query).get("macro") === "true" : false;
|
|
869
|
+
}
|
|
870
|
+
function isMacroVirtualId(id) {
|
|
871
|
+
return id.startsWith("\0") && (hasMacroQuery$1(id) || hasQueryParam$1(id, "definePage"));
|
|
872
|
+
}
|
|
860
873
|
function normalizeRequireBase(importer) {
|
|
861
874
|
if (!importer) return null;
|
|
862
875
|
let normalized = importer;
|
|
863
876
|
if (isVizeVirtual(normalized)) normalized = fromVirtualId(normalized);
|
|
864
|
-
else if (
|
|
877
|
+
else if (isMacroVirtualId(normalized)) normalized = normalized.slice(1).split("?")[0] ?? "";
|
|
865
878
|
return normalized.split("?")[0] ?? null;
|
|
866
879
|
}
|
|
867
880
|
function resolveBareImportWithNode(state, id, importer) {
|
|
@@ -917,10 +930,11 @@ async function resolveIdHook(ctx, state, id, importer, options) {
|
|
|
917
930
|
}
|
|
918
931
|
if (id === "virtual:vize-styles") return RESOLVED_CSS_MODULE;
|
|
919
932
|
if (isBuild && id.startsWith("/@fs/")) return normalizeFsIdForBuild(id);
|
|
920
|
-
if (id
|
|
933
|
+
if (hasMacroQuery$1(id) || hasQueryParam$1(id, "definePage")) {
|
|
921
934
|
const filePath = id.split("?")[0];
|
|
935
|
+
const querySuffix = id.slice(id.indexOf("?"));
|
|
922
936
|
const resolved = resolveVuePath(state, filePath, importer);
|
|
923
|
-
if (resolved && fs.existsSync(resolved)) return `\0${resolved}
|
|
937
|
+
if (resolved && fs.existsSync(resolved)) return `\0${resolved}${querySuffix}`;
|
|
924
938
|
}
|
|
925
939
|
if (id.includes("?vue&type=style") || id.includes("?vue=&type=style")) {
|
|
926
940
|
const params = new URLSearchParams(id.split("?")[1]);
|
|
@@ -928,9 +942,9 @@ async function resolveIdHook(ctx, state, id, importer, options) {
|
|
|
928
942
|
if (params.has("module")) return `\0${id}.module.${lang}`;
|
|
929
943
|
return `\0${id}.${lang}`;
|
|
930
944
|
}
|
|
931
|
-
const isMacroImporter = importer
|
|
945
|
+
const isMacroImporter = importer ? isMacroVirtualId(importer) : false;
|
|
932
946
|
if (importer && (isVizeVirtual(importer) || isMacroImporter)) {
|
|
933
|
-
const cleanImporter = isMacroImporter ? importer.slice(1).
|
|
947
|
+
const cleanImporter = isMacroImporter ? importer.slice(1).split("?")[0] : fromVirtualId(importer);
|
|
934
948
|
state.logger.log(`resolveId from virtual: id=${id}, cleanImporter=${cleanImporter}`);
|
|
935
949
|
if (id.startsWith("#")) try {
|
|
936
950
|
return await ctx.resolve(id, cleanImporter, { skipSelf: true });
|
|
@@ -1069,6 +1083,44 @@ function getVirtualModuleDefines(state, ssr) {
|
|
|
1069
1083
|
...ssr ? state.serverViteDefine : state.clientViteDefine
|
|
1070
1084
|
};
|
|
1071
1085
|
}
|
|
1086
|
+
function hasQueryParam(id, name) {
|
|
1087
|
+
const query = id.split("?")[1];
|
|
1088
|
+
return query ? new URLSearchParams(query).has(name) : false;
|
|
1089
|
+
}
|
|
1090
|
+
function hasMacroQuery(id) {
|
|
1091
|
+
const query = id.split("?")[1];
|
|
1092
|
+
return query ? new URLSearchParams(query).get("macro") === "true" : false;
|
|
1093
|
+
}
|
|
1094
|
+
function normalizeMacroRealPath(realPath) {
|
|
1095
|
+
return realPath.endsWith(".vue.ts") ? realPath.slice(0, -3) : realPath;
|
|
1096
|
+
}
|
|
1097
|
+
function stripVirtualQuery(id) {
|
|
1098
|
+
return normalizeMacroRealPath(id.slice(1).split("?")[0] ?? "");
|
|
1099
|
+
}
|
|
1100
|
+
function findMacroArtifactModule(state, realPath, ssr, kind) {
|
|
1101
|
+
const cache = getEnvironmentCache(state, ssr);
|
|
1102
|
+
realPath = normalizeMacroRealPath(realPath);
|
|
1103
|
+
let compiled = cache.get(realPath) ?? state.cache.get(realPath) ?? state.ssrCache.get(realPath);
|
|
1104
|
+
if (!compiled && fs.existsSync(realPath)) {
|
|
1105
|
+
const source = fs.readFileSync(realPath, "utf-8");
|
|
1106
|
+
compiled = compileFile(realPath, cache, getCompileOptionsForRequest(state, ssr), source);
|
|
1107
|
+
syncCollectedCssForFile(state, realPath, compiled);
|
|
1108
|
+
}
|
|
1109
|
+
return compiled?.macroArtifacts?.find((artifact) => artifact.kind === kind)?.moduleCode ?? null;
|
|
1110
|
+
}
|
|
1111
|
+
function loadDefinePageArtifact(state, realPath, ssr) {
|
|
1112
|
+
return {
|
|
1113
|
+
code: findMacroArtifactModule(state, realPath, ssr, "vue-router.definePage") ?? "export default {}",
|
|
1114
|
+
map: null
|
|
1115
|
+
};
|
|
1116
|
+
}
|
|
1117
|
+
function loadDefinePageMetaArtifact(state, realPath, ssr) {
|
|
1118
|
+
const code = findMacroArtifactModule(state, realPath, ssr, "nuxt.definePageMeta");
|
|
1119
|
+
return code ? {
|
|
1120
|
+
code,
|
|
1121
|
+
map: null
|
|
1122
|
+
} : null;
|
|
1123
|
+
}
|
|
1072
1124
|
function loadHook(state, id, loadOptions) {
|
|
1073
1125
|
const currentBase = loadOptions?.ssr ? state.serverViteBase : state.clientViteBase;
|
|
1074
1126
|
if (id === "\0vize:all-styles.css") return Array.from(state.collectedCss.values()).join("\n\n");
|
|
@@ -1108,8 +1160,11 @@ function loadHook(state, id, loadOptions) {
|
|
|
1108
1160
|
if (fallbackCompiled?.css) return resolveCssImports(fallbackCompiled.css, realPath, state.cssAliasRules, state.server !== null, currentBase);
|
|
1109
1161
|
return "";
|
|
1110
1162
|
}
|
|
1111
|
-
if (id.startsWith("\0") && id
|
|
1112
|
-
|
|
1163
|
+
if (id.startsWith("\0") && hasQueryParam(id, "definePage")) return loadDefinePageArtifact(state, stripVirtualQuery(id), !!loadOptions?.ssr);
|
|
1164
|
+
if (id.startsWith("\0") && hasMacroQuery(id)) {
|
|
1165
|
+
const realPath = stripVirtualQuery(id);
|
|
1166
|
+
const artifactLoad = loadDefinePageMetaArtifact(state, realPath, !!loadOptions?.ssr);
|
|
1167
|
+
if (artifactLoad) return artifactLoad;
|
|
1113
1168
|
if (fs.existsSync(realPath)) {
|
|
1114
1169
|
const setupMatch = fs.readFileSync(realPath, "utf-8").match(/<script\s+setup[^>]*>([\s\S]*?)<\/script>/);
|
|
1115
1170
|
if (setupMatch) return {
|
|
@@ -1181,9 +1236,9 @@ function loadHook(state, id, loadOptions) {
|
|
|
1181
1236
|
return null;
|
|
1182
1237
|
}
|
|
1183
1238
|
async function transformHook(state, code, id, options) {
|
|
1184
|
-
const isMacro = id.startsWith("\0") && id
|
|
1239
|
+
const isMacro = id.startsWith("\0") && (hasMacroQuery(id) || hasQueryParam(id, "definePage"));
|
|
1185
1240
|
if (isVizeVirtual(id) || isMacro) {
|
|
1186
|
-
const realPath = isMacro ? id
|
|
1241
|
+
const realPath = isMacro ? stripVirtualQuery(id) : fromVirtualId(id);
|
|
1187
1242
|
try {
|
|
1188
1243
|
const result = await transformWithOxc(code, realPath, { lang: "ts" });
|
|
1189
1244
|
const defines = getVirtualModuleDefines(state, options?.ssr ?? false);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vizejs/vite-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.76.0",
|
|
4
4
|
"description": "High-performance native Vite plugin for Vue SFC compilation powered by Vize",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"compiler",
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@vizejs/native": "0.
|
|
36
|
+
"@vizejs/native": "0.76.0",
|
|
37
37
|
"tinyglobby": "0.2.16",
|
|
38
|
-
"vize": "0.
|
|
38
|
+
"vize": "0.76.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/node": "25.6.0",
|