@vizejs/vite-plugin 0.92.0 → 0.94.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.
Files changed (2) hide show
  1. package/dist/index.mjs +59 -112
  2. package/package.json +3 -3
package/dist/index.mjs CHANGED
@@ -5,6 +5,7 @@ import path from "node:path";
5
5
  import { CONFIG_FILE_NAMES, defineConfig, loadConfig } from "vize";
6
6
  import { glob } from "tinyglobby";
7
7
  import * as native from "@vizejs/native";
8
+ import { classifyVitePluginRequest } from "@vizejs/native";
8
9
  import { pathToFileURL } from "node:url";
9
10
  import { transformWithOxc } from "vite";
10
11
  //#region src/hmr.ts
@@ -509,28 +510,10 @@ ${output}`;
509
510
  }
510
511
  const VIZE_SSR_PREFIX = "\0vize-ssr:";
511
512
  const RESOLVED_CSS_MODULE = "\0vize:all-styles.css";
512
- /** Check if a module ID is a vize-compiled virtual module */
513
- function isVizeVirtual(id) {
514
- return isVizeVirtualVueModuleId(id);
515
- }
516
- function isVizeVirtualVueModuleId(id) {
517
- return id.startsWith("\0") && /\.vue\.ts(?:\?|$)/.test(id);
518
- }
519
- function isVizeSsrVirtual(id) {
520
- return id.startsWith(VIZE_SSR_PREFIX);
521
- }
522
513
  /** Create a virtual module ID from a real .vue file path */
523
514
  function toVirtualId(realPath, ssr = false) {
524
515
  return ssr ? `${VIZE_SSR_PREFIX}${realPath}.ts` : "\0" + realPath + ".ts";
525
516
  }
526
- /** Extract the real .vue file path from a virtual module ID */
527
- function fromVirtualId(virtualId) {
528
- return normalizeVizeVirtualVueModuleId(virtualId).split("?")[0];
529
- }
530
- function normalizeVizeVirtualVueModuleId(id) {
531
- const prefix = isVizeSsrVirtual(id) ? 10 : 1;
532
- return id.slice(prefix).replace(/\.ts(?=\?|$)/, "");
533
- }
534
517
  function escapeRegExp(value) {
535
518
  return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
536
519
  }
@@ -540,12 +523,6 @@ function toBrowserImportPrefix(replacement) {
540
523
  if (path.isAbsolute(replacement) && fs.existsSync(replacement)) return `/@fs${normalized}`;
541
524
  return normalized;
542
525
  }
543
- function normalizeFsIdForBuild(id) {
544
- const [pathPart, queryPart] = id.split("?");
545
- if (!pathPart.startsWith("/@fs/")) return id;
546
- const normalizedPath = pathPart.slice(4);
547
- return queryPart ? `${normalizedPath}?${queryPart}` : normalizedPath;
548
- }
549
526
  function rewriteDynamicTemplateImports(code, aliasRules) {
550
527
  let rewritten = code;
551
528
  for (const rule of aliasRules) {
@@ -877,31 +854,19 @@ function resolveVuePath(state, id, importer) {
877
854
  else if (id.startsWith("/") && !fs.existsSync(id)) resolved = path.resolve(state.root, id.slice(1));
878
855
  else if (path.isAbsolute(id)) resolved = id;
879
856
  else if (importer) {
880
- const realImporter = isVizeVirtual(importer) ? fromVirtualId(importer) : importer;
857
+ const importerRequest = classifyVitePluginRequest(importer);
858
+ const realImporter = importerRequest.vizeVirtualPath ?? importerRequest.strippedVirtualPath ?? importer;
881
859
  resolved = path.resolve(path.dirname(realImporter), id);
882
860
  } else resolved = path.resolve(state.root, id);
883
861
  if (!path.isAbsolute(resolved)) resolved = path.resolve(state.root, resolved);
884
862
  return path.normalize(resolved);
885
863
  }
886
- function hasQueryParam$1(id, name) {
887
- const query = id.split("?")[1];
888
- return query ? new URLSearchParams(query).has(name) : false;
889
- }
890
- function hasMacroQuery$1(id) {
891
- const query = id.split("?")[1];
892
- return query ? new URLSearchParams(query).get("macro") === "true" : false;
893
- }
894
- function isMacroVirtualId(id) {
895
- return id.startsWith("\0") && (hasMacroQuery$1(id) || hasQueryParam$1(id, "definePage"));
896
- }
897
- function isVueSfcPath$1(id) {
898
- return (id.split("?")[0] ?? id).endsWith(".vue");
899
- }
900
864
  function normalizeRequireBase(importer) {
901
865
  if (!importer) return null;
902
866
  let normalized = importer;
903
- if (isVizeVirtual(normalized)) normalized = fromVirtualId(normalized);
904
- else if (isMacroVirtualId(normalized)) normalized = normalized.slice(1).split("?")[0] ?? "";
867
+ const request = classifyVitePluginRequest(normalized);
868
+ if (request.vizeVirtualPath) normalized = request.vizeVirtualPath;
869
+ else if (request.isMacroVirtualId) normalized = request.strippedVirtualPath ?? "";
905
870
  return normalized.split("?")[0] ?? null;
906
871
  }
907
872
  function splitIdQuery(id) {
@@ -1002,10 +967,12 @@ async function resolveAliasedVueImport(ctx, state, id, importer, isSsrRequest, h
1002
967
  }
1003
968
  async function resolveIdHook(ctx, state, id, importer, options) {
1004
969
  const isBuild = state.server === null;
1005
- const isSsrRequest = !!options?.ssr || (importer ? isVizeSsrVirtual(importer) : false);
970
+ const importerRequest = importer ? classifyVitePluginRequest(importer) : null;
971
+ const isSsrRequest = !!options?.ssr || (importerRequest?.isVizeSsrVirtual ?? false);
972
+ const request = classifyVitePluginRequest(id);
1006
973
  if (id.startsWith("\0")) {
1007
- if (isVizeVirtual(id)) {
1008
- if (isSsrRequest && !isVizeSsrVirtual(id)) return toVirtualId(fromVirtualId(id), true);
974
+ if (request.isVizeVirtual) {
975
+ if (isSsrRequest && !request.isVizeSsrVirtual && request.vizeVirtualPath) return toVirtualId(request.vizeVirtualPath, true);
1009
976
  return null;
1010
977
  }
1011
978
  if (id.startsWith("\0vize:")) {
@@ -1022,7 +989,7 @@ async function resolveIdHook(ctx, state, id, importer, options) {
1022
989
  const querySuffix = queryPart ? `?${queryPart}` : "";
1023
990
  state.logger.log(`resolveId: redirecting \0-prefixed non-vue ID to ${pathPart}${querySuffix}`);
1024
991
  const redirected = pathPart + querySuffix;
1025
- return isBuild ? normalizeFsIdForBuild(redirected) : redirected;
992
+ return isBuild ? classifyVitePluginRequest(redirected).normalizedFsId ?? redirected : redirected;
1026
993
  }
1027
994
  return null;
1028
995
  }
@@ -1031,29 +998,24 @@ async function resolveIdHook(ctx, state, id, importer, options) {
1031
998
  if (realPath.endsWith(".ts")) realPath = realPath.slice(0, -3);
1032
999
  state.logger.log(`resolveId: redirecting stale vize: ID to ${realPath}`);
1033
1000
  const resolved = await ctx.resolve(realPath, importer, { skipSelf: true });
1034
- if (resolved && isBuild && resolved.id.startsWith("/@fs/")) return {
1001
+ const normalizedFsId = resolved ? classifyVitePluginRequest(resolved.id).normalizedFsId : null;
1002
+ if (resolved && isBuild && normalizedFsId) return {
1035
1003
  ...resolved,
1036
- id: normalizeFsIdForBuild(resolved.id)
1004
+ id: normalizedFsId
1037
1005
  };
1038
1006
  return resolved;
1039
1007
  }
1040
1008
  if (id === "virtual:vize-styles") return RESOLVED_CSS_MODULE;
1041
- if (isBuild && id.startsWith("/@fs/")) return normalizeFsIdForBuild(id);
1042
- if ((hasMacroQuery$1(id) || hasQueryParam$1(id, "definePage")) && isVueSfcPath$1(id)) {
1043
- const filePath = id.split("?")[0];
1044
- const querySuffix = id.slice(id.indexOf("?"));
1045
- const resolved = resolveVuePath(state, filePath, importer);
1046
- if (resolved && fs.existsSync(resolved)) return `\0${resolved}${querySuffix}`;
1009
+ if (isBuild && request.normalizedFsId) return request.normalizedFsId;
1010
+ if ((request.hasMacroQuery || request.hasDefinePageQuery) && request.isVueSfcPath) {
1011
+ const resolved = resolveVuePath(state, request.path, importer);
1012
+ if (resolved && fs.existsSync(resolved)) return `\0${resolved}${request.querySuffix}`;
1047
1013
  }
1048
- if (id.includes("?vue&type=style") || id.includes("?vue=&type=style")) {
1049
- const params = new URLSearchParams(id.split("?")[1]);
1050
- const lang = params.get("lang") || "css";
1051
- if (params.has("module")) return `\0${id}.module.${lang}`;
1052
- return `\0${id}.${lang}`;
1053
- }
1054
- const isMacroImporter = importer ? isMacroVirtualId(importer) : false;
1055
- if (importer && (isVizeVirtual(importer) || isMacroImporter)) {
1056
- const cleanImporter = isMacroImporter ? importer.slice(1).split("?")[0] : fromVirtualId(importer);
1014
+ if (request.isVueStyleQuery && request.styleVirtualSuffix) return `\0${id}${request.styleVirtualSuffix}`;
1015
+ const isMacroImporter = importerRequest?.isMacroVirtualId ?? false;
1016
+ const isVizeVirtualImporter = importerRequest?.isVizeVirtual ?? false;
1017
+ if (importer && (isVizeVirtualImporter || isMacroImporter)) {
1018
+ const cleanImporter = isMacroImporter ? importerRequest?.strippedVirtualPath ?? "" : importerRequest?.vizeVirtualPath ?? "";
1057
1019
  state.logger.log(`resolveId from virtual: id=${id}, cleanImporter=${cleanImporter}`);
1058
1020
  if (id.startsWith("#")) try {
1059
1021
  return await ctx.resolve(id, cleanImporter, { skipSelf: true });
@@ -1074,9 +1036,10 @@ async function resolveIdHook(ctx, state, id, importer, options) {
1074
1036
  const resolved = await ctx.resolve(id, cleanImporter, { skipSelf: true });
1075
1037
  if (resolved) {
1076
1038
  state.logger.log(`resolveId: resolved bare ${id} to ${resolved.id} via Vite resolver`);
1077
- if (isBuild && resolved.id.startsWith("/@fs/")) return {
1039
+ const normalizedFsId = classifyVitePluginRequest(resolved.id).normalizedFsId;
1040
+ if (isBuild && normalizedFsId) return {
1078
1041
  ...resolved,
1079
- id: normalizeFsIdForBuild(resolved.id)
1042
+ id: normalizedFsId
1080
1043
  };
1081
1044
  const nodeResolved = resolveBareImportCandidatesWithNode(state, id, cleanImporter, resolved.id);
1082
1045
  if (nodeResolved) {
@@ -1097,9 +1060,10 @@ async function resolveIdHook(ctx, state, id, importer, options) {
1097
1060
  const resolved = await ctx.resolve(aliasRequest, cleanImporter, { skipSelf: true });
1098
1061
  if (resolved) {
1099
1062
  state.logger.log(`resolveId: resolved aliased bare ${id} to ${resolved.id} via Vite resolver`);
1100
- if (isBuild && resolved.id.startsWith("/@fs/")) return {
1063
+ const normalizedFsId = classifyVitePluginRequest(resolved.id).normalizedFsId;
1064
+ if (isBuild && normalizedFsId) return {
1101
1065
  ...resolved,
1102
- id: normalizeFsIdForBuild(resolved.id)
1066
+ id: normalizedFsId
1103
1067
  };
1104
1068
  const nodeResolved = resolveBareImportCandidatesWithNode(state, id, cleanImporter, resolved.id);
1105
1069
  if (nodeResolved) {
@@ -1122,9 +1086,10 @@ async function resolveIdHook(ctx, state, id, importer, options) {
1122
1086
  const resolved = await ctx.resolve(id, cleanImporter, { skipSelf: true });
1123
1087
  if (resolved) {
1124
1088
  state.logger.log(`resolveId: resolved ${id} to ${resolved.id} via Vite resolver`);
1125
- if (isBuild && resolved.id.startsWith("/@fs/")) return {
1089
+ const normalizedFsId = classifyVitePluginRequest(resolved.id).normalizedFsId;
1090
+ if (isBuild && normalizedFsId) return {
1126
1091
  ...resolved,
1127
- id: normalizeFsIdForBuild(resolved.id)
1092
+ id: normalizedFsId
1128
1093
  };
1129
1094
  return resolved;
1130
1095
  }
@@ -1203,8 +1168,9 @@ export default defineComponent({
1203
1168
  });
1204
1169
  `;
1205
1170
  function getBoundaryPlaceholderCode(realPath, ssr) {
1206
- if (ssr && realPath.endsWith(".client.vue")) return SERVER_PLACEHOLDER_CODE;
1207
- if (!ssr && realPath.endsWith(".server.vue")) return SERVER_PLACEHOLDER_CODE;
1171
+ const boundaryKind = classifyVitePluginRequest(realPath).boundaryKind;
1172
+ if (ssr && boundaryKind === "client") return SERVER_PLACEHOLDER_CODE;
1173
+ if (!ssr && boundaryKind === "server") return SERVER_PLACEHOLDER_CODE;
1208
1174
  return null;
1209
1175
  }
1210
1176
  function getOxcDumpPath(root, realPath) {
@@ -1222,26 +1188,9 @@ function getVirtualModuleDefines(state, ssr) {
1222
1188
  ...ssr ? state.serverViteDefine : state.clientViteDefine
1223
1189
  };
1224
1190
  }
1225
- function hasQueryParam(id, name) {
1226
- const query = id.split("?")[1];
1227
- return query ? new URLSearchParams(query).has(name) : false;
1228
- }
1229
- function hasMacroQuery(id) {
1230
- const query = id.split("?")[1];
1231
- return query ? new URLSearchParams(query).get("macro") === "true" : false;
1232
- }
1233
- function normalizeMacroRealPath(realPath) {
1234
- return realPath.endsWith(".vue.ts") ? realPath.slice(0, -3) : realPath;
1235
- }
1236
- function isVueSfcPath(realPath) {
1237
- return normalizeMacroRealPath(realPath).endsWith(".vue");
1238
- }
1239
- function stripVirtualQuery(id) {
1240
- return normalizeMacroRealPath(id.slice(1).split("?")[0] ?? "");
1241
- }
1242
1191
  function findMacroArtifactModule(state, realPath, ssr, kind) {
1243
1192
  const cache = getEnvironmentCache(state, ssr);
1244
- realPath = normalizeMacroRealPath(realPath);
1193
+ realPath = classifyVitePluginRequest(realPath).normalizedVuePath;
1245
1194
  let compiled = cache.get(realPath) ?? state.cache.get(realPath) ?? state.ssrCache.get(realPath);
1246
1195
  if (!compiled && fs.existsSync(realPath)) {
1247
1196
  const source = fs.readFileSync(realPath, "utf-8");
@@ -1265,19 +1214,17 @@ function loadDefinePageMetaArtifact(state, realPath, ssr) {
1265
1214
  }
1266
1215
  function loadHook(state, id, loadOptions) {
1267
1216
  const currentBase = loadOptions?.ssr ? state.serverViteBase : state.clientViteBase;
1217
+ const request = classifyVitePluginRequest(id);
1268
1218
  if (id === "\0vize:all-styles.css") return Array.from(state.collectedCss.values()).join("\n\n");
1269
1219
  let styleId = id;
1270
1220
  if (id.startsWith("\0") && id.includes("?vue")) styleId = id.slice(1).replace(/\.module\.\w+$/, "").replace(/\.\w+$/, "");
1271
- if (styleId.includes("?vue&type=style") || styleId.includes("?vue=&type=style")) {
1272
- const [filename, queryString] = styleId.split("?");
1273
- const realPath = isVizeVirtual(filename) ? fromVirtualId(filename) : filename;
1274
- const params = new URLSearchParams(queryString);
1275
- const indexStr = params.get("index");
1276
- const lang = params.get("lang");
1277
- params.has("module");
1278
- const scoped = params.get("scoped");
1221
+ const styleRequest = classifyVitePluginRequest(styleId);
1222
+ if (styleRequest.isVueStyleQuery) {
1223
+ const realPath = classifyVitePluginRequest(styleRequest.path).vizeVirtualPath ?? styleRequest.path;
1224
+ const lang = styleRequest.styleLang ?? null;
1225
+ const scoped = styleRequest.styleScoped ?? null;
1279
1226
  const fallbackCompiled = state.cache.get(realPath) ?? state.ssrCache.get(realPath);
1280
- const blockIndex = indexStr !== null ? parseInt(indexStr, 10) : -1;
1227
+ const blockIndex = styleRequest.styleIndex ?? -1;
1281
1228
  if (fallbackCompiled?.styles && blockIndex >= 0 && blockIndex < fallbackCompiled.styles.length) {
1282
1229
  const block = fallbackCompiled.styles[blockIndex];
1283
1230
  let styleContent = block.content;
@@ -1302,13 +1249,13 @@ function loadHook(state, id, loadOptions) {
1302
1249
  if (fallbackCompiled?.css) return resolveCssImports(fallbackCompiled.css, realPath, state.cssAliasRules, state.server !== null, currentBase);
1303
1250
  return "";
1304
1251
  }
1305
- if (id.startsWith("\0") && hasQueryParam(id, "definePage")) {
1306
- const realPath = stripVirtualQuery(id);
1307
- if (isVueSfcPath(realPath)) return loadDefinePageArtifact(state, realPath, !!loadOptions?.ssr);
1252
+ if (id.startsWith("\0") && request.hasDefinePageQuery) {
1253
+ const realPath = request.strippedVirtualPath ?? "";
1254
+ if (request.isVueSfcPath) return loadDefinePageArtifact(state, realPath, !!loadOptions?.ssr);
1308
1255
  }
1309
- if (id.startsWith("\0") && hasMacroQuery(id)) {
1310
- const realPath = stripVirtualQuery(id);
1311
- if (isVueSfcPath(realPath)) {
1256
+ if (id.startsWith("\0") && request.hasMacroQuery) {
1257
+ const realPath = request.strippedVirtualPath ?? "";
1258
+ if (request.isVueSfcPath) {
1312
1259
  const artifactLoad = loadDefinePageMetaArtifact(state, realPath, !!loadOptions?.ssr);
1313
1260
  if (artifactLoad) return artifactLoad;
1314
1261
  if (fs.existsSync(realPath)) {
@@ -1324,9 +1271,9 @@ function loadHook(state, id, loadOptions) {
1324
1271
  };
1325
1272
  }
1326
1273
  }
1327
- if (isVizeVirtual(id)) {
1328
- const realPath = fromVirtualId(id);
1329
- const isSsr = isVizeSsrVirtual(id) || !!loadOptions?.ssr;
1274
+ if (request.isVizeVirtual) {
1275
+ const realPath = request.vizeVirtualPath ?? "";
1276
+ const isSsr = request.isVizeSsrVirtual || !!loadOptions?.ssr;
1330
1277
  if (!realPath.endsWith(".vue")) {
1331
1278
  state.logger.log(`load: skipping non-vue virtual module ${realPath}`);
1332
1279
  return null;
@@ -1371,9 +1318,9 @@ function loadHook(state, id, loadOptions) {
1371
1318
  if (id.startsWith("\0")) {
1372
1319
  const afterPrefix = id.startsWith("\0vize:") ? id.slice(6) : id.slice(1);
1373
1320
  if (afterPrefix.includes("?commonjs-")) return null;
1374
- const [pathPart, queryPart] = afterPrefix.split("?");
1375
- const querySuffix = queryPart ? `?${queryPart}` : "";
1376
- const fsPath = pathPart.startsWith("/@fs/") ? pathPart.slice(4) : pathPart;
1321
+ const leakedRequest = classifyVitePluginRequest(afterPrefix);
1322
+ const fsPath = leakedRequest.normalizedFsId ? classifyVitePluginRequest(leakedRequest.normalizedFsId).path : leakedRequest.path;
1323
+ const querySuffix = leakedRequest.querySuffix;
1377
1324
  if (fsPath.startsWith("/") && fs.existsSync(fsPath) && fs.statSync(fsPath).isFile()) {
1378
1325
  const importPath = state.server === null ? `${pathToFileURL(fsPath).href}${querySuffix}` : "/@fs" + fsPath + querySuffix;
1379
1326
  state.logger.log(`load: proxying \0-prefixed file ${id} -> re-export from ${importPath}`);
@@ -1383,9 +1330,9 @@ function loadHook(state, id, loadOptions) {
1383
1330
  return null;
1384
1331
  }
1385
1332
  async function transformHook(state, code, id, options) {
1386
- const isMacro = id.startsWith("\0") && (hasMacroQuery(id) || hasQueryParam(id, "definePage"));
1387
- if (isVizeVirtual(id) || isMacro) {
1388
- const realPath = isMacro ? stripVirtualQuery(id) : fromVirtualId(id);
1333
+ const request = classifyVitePluginRequest(id);
1334
+ if (request.isVizeVirtual || request.isMacroVirtualId) {
1335
+ const realPath = request.isMacroVirtualId ? request.strippedVirtualPath ?? "" : request.vizeVirtualPath ?? "";
1389
1336
  try {
1390
1337
  const result = await transformWithOxc(code, realPath, {
1391
1338
  lang: "ts",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/vite-plugin",
3
- "version": "0.92.0",
3
+ "version": "0.94.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.92.0",
36
+ "@vizejs/native": "0.94.0",
37
37
  "tinyglobby": "0.2.16",
38
- "vize": "0.92.0"
38
+ "vize": "0.94.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/node": "25.7.0",