@vizejs/vite-plugin 0.322.0 → 0.323.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 CHANGED
@@ -1,4 +1,4 @@
1
- import { a as VizeVueVersion, c as VizeInspectorLintPlanRequest, d as LoadConfigOptions, f as ResolvedVizeConfig, i as VizeOptions, l as VizeInspectorOptions, m as VizeConfig, n as MacroArtifact, o as VizeVueFeatures, p as UserConfigExport, r as VizeCompatibilityOptions, s as VizeInspectorLintPlanProvider, t as CompiledModule, u as ConfigEnv } from "./types-dAZFEbN_.mjs";
1
+ import { a as VizeVueVersion, c as VizeInspectorLintPlanRequest, d as LoadConfigOptions, f as ResolvedVizeConfig, i as VizeOptions, l as VizeInspectorOptions, m as VizeConfig, n as MacroArtifact, o as VizeVueFeatures, p as UserConfigExport, r as VizeCompatibilityOptions, s as VizeInspectorLintPlanProvider, t as CompiledModule, u as ConfigEnv } from "./types-DR5IFFd7.mjs";
2
2
  import { Plugin } from "vite";
3
3
 
4
4
  //#region src/virtual.d.ts
package/dist/index.mjs CHANGED
@@ -597,6 +597,13 @@ function generateOutputWithMap(compiled, options) {
597
597
  };
598
598
  }
599
599
  const RESOLVED_CSS_MODULE = "\0vize:all-styles.css";
600
+ /** Check if a module ID is a vize-compiled virtual module */
601
+ function isVizeVirtual(id) {
602
+ return classifyVitePluginRequest(id).isVizeVirtual;
603
+ }
604
+ function isVizeSsrVirtual(id) {
605
+ return classifyVitePluginRequest(id).isVizeSsrVirtual;
606
+ }
600
607
  /** Create a virtual module ID from a real .vue file path */
601
608
  function toVirtualId(realPath, ssr = false) {
602
609
  return createViteVirtualId(realPath, ssr);
@@ -2571,7 +2578,6 @@ function loadCompiledSfcModule(state, realPath, isSsr, currentBase, loadOptions)
2571
2578
  rewritten.edit(rewriteDynamicTemplateImports(rewritten.code, state.dynamicImportAliasRules));
2572
2579
  rewritten.edit(rewriteStaticAssetUrls(rewritten.code, state.dynamicImportAliasRules));
2573
2580
  rewritten.edit(rewriteImportMetaGlobBase(rewritten.code, realPath, state.root));
2574
- if (!loadOptions?.ssr) state.pendingHmrUpdateTypes.delete(realPath);
2575
2581
  return {
2576
2582
  code: rewritten.code,
2577
2583
  map: rewritten.map
@@ -2765,30 +2771,46 @@ function getVueModuleFileCandidates(vueFile) {
2765
2771
  function getStyleModuleFileCandidates(styleId) {
2766
2772
  return unique([styleId, `${styleId}.css`]);
2767
2773
  }
2768
- function collectModulesByFile(server, fileIds) {
2774
+ async function collectModulesByFile(server, fileIds) {
2769
2775
  const modules = /* @__PURE__ */ new Set();
2776
+ const graph = server.moduleGraph;
2770
2777
  for (const fileId of fileIds) {
2771
- const matched = server.moduleGraph.getModulesByFile(fileId);
2772
- if (!matched) continue;
2773
- for (const mod of matched) modules.add(mod);
2778
+ const add = (module) => {
2779
+ if (module) modules.add(module);
2780
+ };
2781
+ add(graph.getModuleById?.(fileId));
2782
+ if (!fileId.startsWith("\0")) try {
2783
+ add(await graph.getModuleByUrl?.(fileId));
2784
+ } catch {}
2785
+ for (const module of graph.getModulesByFile(fileId) ?? []) add(module);
2774
2786
  }
2775
2787
  return modules;
2776
2788
  }
2789
+ function preferAcceptingClientModules(modules, requireAcceptingClientModule = false) {
2790
+ const accepting = [...modules].filter((module) => {
2791
+ if (isVizeVirtual(module.url)) return !isVizeSsrVirtual(module.url);
2792
+ return fromPluginVisibleVirtualId(module.url) !== null && !isPluginVisibleSsrVirtualId(module.url);
2793
+ });
2794
+ if (accepting.length > 0) return new Set(accepting);
2795
+ return requireAcceptingClientModule ? /* @__PURE__ */ new Set() : modules;
2796
+ }
2777
2797
  function invalidateModules(server, modules) {
2778
2798
  for (const module of modules) server.moduleGraph.invalidateModule(module);
2779
2799
  }
2780
- async function handleHotUpdateHook(state, ctx) {
2800
+ async function handleHotUpdateHook(state, ctx, options = {}) {
2781
2801
  const { file, server, read } = ctx;
2782
2802
  const dependencyOwners = getVueFilesDependingOn(state, file);
2783
2803
  if (dependencyOwners.length > 0) {
2784
2804
  const affectedModules = /* @__PURE__ */ new Set();
2785
2805
  for (const vueFile of dependencyOwners) {
2806
+ const collectedModules = await collectModulesByFile(server, getVueModuleFileCandidates(vueFile));
2807
+ const modules = options.requireAcceptingClientModule ? preferAcceptingClientModules(collectedModules, true) : collectedModules;
2808
+ if (options.requireAcceptingClientModule && modules.size === 0) continue;
2786
2809
  state.cache.delete(vueFile);
2787
2810
  state.ssrCache.delete(vueFile);
2788
2811
  state.collectedCss.delete(vueFile);
2789
2812
  state.precompileMetadata.delete(vueFile);
2790
2813
  state.pendingHmrUpdateTypes.set(vueFile, "full-reload");
2791
- const modules = collectModulesByFile(server, getVueModuleFileCandidates(vueFile));
2792
2814
  for (const module of modules) {
2793
2815
  server.moduleGraph.invalidateModule(module);
2794
2816
  affectedModules.add(module);
@@ -2798,6 +2820,8 @@ async function handleHotUpdateHook(state, ctx) {
2798
2820
  return [...affectedModules];
2799
2821
  }
2800
2822
  if (file.endsWith(".vue") && state.filter(file)) try {
2823
+ const initialModules = options.requireAcceptingClientModule ? preferAcceptingClientModules(await collectModulesByFile(server, getVueModuleFileCandidates(file)), true) : void 0;
2824
+ if (initialModules?.size === 0) return [];
2801
2825
  const source = await read();
2802
2826
  const prevCompiled = state.cache.get(file);
2803
2827
  compileFile(file, state.cache, getCompileOptionsForRequest(state, false), source);
@@ -2819,7 +2843,7 @@ async function handleHotUpdateHook(state, ctx) {
2819
2843
  }
2820
2844
  const updateType = detectHmrUpdateType(prevCompiled, newCompiled);
2821
2845
  state.logger.log(`Re-compiled: ${path.relative(state.root, file)} (${updateType})`);
2822
- const modules = collectModulesByFile(server, getVueModuleFileCandidates(file));
2846
+ const modules = preferAcceptingClientModules(initialModules ?? await collectModulesByFile(server, getVueModuleFileCandidates(file)), options.requireAcceptingClientModule);
2823
2847
  const hasDelegated = hasDelegatedStyles(newCompiled);
2824
2848
  if (hasDelegated && updateType === "style-only") {
2825
2849
  const affectedModules = /* @__PURE__ */ new Set();
@@ -2831,7 +2855,7 @@ async function handleHotUpdateHook(state, ctx) {
2831
2855
  if (block.scoped) params.set("scoped", `data-v-${newCompiled.scopeId}`);
2832
2856
  params.set("lang", block.lang ?? "css");
2833
2857
  if (block.module !== false) params.set("module", typeof block.module === "string" ? block.module : "");
2834
- const styleMods = collectModulesByFile(server, getStyleModuleFileCandidates(`${file}?${params.toString()}`));
2858
+ const styleMods = await collectModulesByFile(server, getStyleModuleFileCandidates(`${file}?${params.toString()}`));
2835
2859
  for (const mod of styleMods) affectedModules.add(mod);
2836
2860
  }
2837
2861
  if (affectedModules.size > 0) return [...affectedModules];
@@ -2859,6 +2883,7 @@ async function handleHotUpdateHook(state, ctx) {
2859
2883
  state.pendingHmrUpdateTypes.delete(file);
2860
2884
  } catch (e) {
2861
2885
  state.logger.error(`Re-compilation failed for ${file}:`, e);
2886
+ options.onRecompileError?.(e);
2862
2887
  }
2863
2888
  }
2864
2889
  function handleGenerateBundleHook(state, emitFile, bundle) {
@@ -2890,6 +2915,28 @@ function attachComponentsCssToEntryChunks(bundle, cssFileName) {
2890
2915
  }
2891
2916
  }
2892
2917
  //#endregion
2918
+ //#region src/plugin/hot-update-environment.ts
2919
+ async function handleHotUpdateEnvironmentHook(state, environment, options) {
2920
+ if (environment.name !== "client" && environment.name !== "browser") return options.modules;
2921
+ const server = {
2922
+ moduleGraph: environment.moduleGraph,
2923
+ ws: { send: environment.hot.send.bind(environment.hot) }
2924
+ };
2925
+ let recompileFailed = false;
2926
+ const modules = await handleHotUpdateHook(state, {
2927
+ ...options,
2928
+ server
2929
+ }, {
2930
+ requireAcceptingClientModule: true,
2931
+ onRecompileError: () => {
2932
+ recompileFailed = true;
2933
+ }
2934
+ });
2935
+ if (recompileFailed) return;
2936
+ if (modules === void 0 && options.file.endsWith(".vue") && state.filter(options.file)) return [];
2937
+ return modules;
2938
+ }
2939
+ //#endregion
2893
2940
  //#region src/plugin/compat.ts
2894
2941
  function createVueCompatPlugin(state) {
2895
2942
  let compilerSfc = null;
@@ -3537,9 +3584,13 @@ function parseDefine(value) {
3537
3584
  return value;
3538
3585
  }
3539
3586
  }
3540
- /** Resolve the Options API runtime define with plugin-vue's precedence. */
3541
- function resolveOptionsApiFlag(option, define) {
3542
- return option ?? parseDefine(define) ?? true;
3587
+ /** Resolve Vue runtime defines with plugin-vue's precedence and defaults. */
3588
+ function resolveVueFeatureDefines(features, define, command) {
3589
+ return {
3590
+ __VUE_OPTIONS_API__: features?.optionsAPI ?? parseDefine(define?.__VUE_OPTIONS_API__) ?? true,
3591
+ __VUE_PROD_DEVTOOLS__: command === "serve",
3592
+ __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: (features?.prodHydrationMismatchDetails || parseDefine(define?.__VUE_PROD_HYDRATION_MISMATCH_DETAILS__)) ?? false
3593
+ };
3543
3594
  }
3544
3595
  //#endregion
3545
3596
  //#region src/plugin/index.ts
@@ -3599,11 +3650,7 @@ function vize(options = {}) {
3599
3650
  config(userConfig, env) {
3600
3651
  patchCssModuleGenerateScopedName(userConfig);
3601
3652
  return {
3602
- define: {
3603
- __VUE_OPTIONS_API__: resolveOptionsApiFlag(options.features?.optionsAPI, userConfig.define?.__VUE_OPTIONS_API__),
3604
- __VUE_PROD_DEVTOOLS__: env.command === "serve",
3605
- __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: false
3606
- },
3653
+ define: resolveVueFeatureDefines(options.features, userConfig.define, env.command),
3607
3654
  optimizeDeps: { exclude: ["virtual:vize-styles"] }
3608
3655
  };
3609
3656
  },
@@ -3717,6 +3764,9 @@ function vize(options = {}) {
3717
3764
  async transform(code, id, transformOptions) {
3718
3765
  return transformHook(state, code, id, transformOptions);
3719
3766
  },
3767
+ async hotUpdate(options) {
3768
+ return handleHotUpdateEnvironmentHook(state, this.environment, options);
3769
+ },
3720
3770
  async handleHotUpdate(ctx) {
3721
3771
  return handleHotUpdateHook(state, ctx);
3722
3772
  },
@@ -1,4 +1,4 @@
1
- import { f as ResolvedVizeConfig } from "../types-dAZFEbN_.mjs";
1
+ import { f as ResolvedVizeConfig } from "../types-DR5IFFd7.mjs";
2
2
  import { ResolvedConfig } from "vite";
3
3
 
4
4
  //#region src/internal/config-bridge.d.ts
@@ -730,6 +730,11 @@ interface VizeVueFeatures {
730
730
  * @default true
731
731
  */
732
732
  optionsAPI?: boolean;
733
+ /**
734
+ * Enable detailed hydration mismatch errors in production bundles.
735
+ * @default false
736
+ */
737
+ prodHydrationMismatchDetails?: boolean;
733
738
  }
734
739
  //#endregion
735
740
  //#region src/utils/module-output.d.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/vite-plugin",
3
- "version": "0.322.0",
3
+ "version": "0.323.0",
4
4
  "description": "High-performance native Vite plugin for Vue SFC compilation powered by Vize",
5
5
  "keywords": [
6
6
  "compiler",
@@ -45,10 +45,10 @@
45
45
  "access": "public"
46
46
  },
47
47
  "dependencies": {
48
- "@vizejs/native": "0.322.0",
48
+ "@vizejs/native": "0.323.0",
49
49
  "oxc-parser": "0.133.0",
50
50
  "tinyglobby": "0.2.16",
51
- "vize": "0.322.0"
51
+ "vize": "0.323.0"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@types/node": "25.9.2",