@vizejs/vite-plugin 0.306.0 → 0.312.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/README.md CHANGED
@@ -181,8 +181,9 @@ interface VizeNativeOptions {
181
181
  ssr?: boolean;
182
182
 
183
183
  /**
184
- * Enable source map generation
185
- * @default true in development, false in production
184
+ * Enable source map generation. The emitted map's `sources` names the
185
+ * authored `.vue` file, not the virtual `.vue.ts` module.
186
+ * @default true in development, false in production unless `build.sourcemap` is set
186
187
  */
187
188
  sourceMap?: boolean;
188
189
 
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as VizeVueVersion, c as ResolvedVizeConfig, i as VizeOptions, l as UserConfigExport, n as MacroArtifact, o as ConfigEnv, r as VizeCompatibilityOptions, s as LoadConfigOptions, t as CompiledModule, u as VizeConfig } from "./types-x-lq08Y8.mjs";
1
+ import { a as VizeVueVersion, c as ResolvedVizeConfig, i as VizeOptions, l as UserConfigExport, n as MacroArtifact, o as ConfigEnv, r as VizeCompatibilityOptions, s as LoadConfigOptions, t as CompiledModule, u as VizeConfig } from "./types-Cm3dJq25.mjs";
2
2
  import { Plugin } from "vite";
3
3
 
4
4
  //#region src/virtual.d.ts
package/dist/index.mjs CHANGED
@@ -4,9 +4,9 @@ import crypto, { createHash } from "node:crypto";
4
4
  import * as native from "@vizejs/native";
5
5
  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";
6
6
  import { parseSync } from "oxc-parser";
7
+ import path from "node:path";
7
8
  import fs from "node:fs";
8
9
  import { glob } from "tinyglobby";
9
- import path from "node:path";
10
10
  import zlib from "node:zlib";
11
11
  import { pathToFileURL } from "node:url";
12
12
  import * as vite from "vite";
@@ -230,6 +230,89 @@ function insertBeforeSfcMainDefaultExport(code, insertion, options = {}) {
230
230
  return `${code.slice(0, exportStart)}${insertion}\n${code.slice(exportStart)}`;
231
231
  }
232
232
  //#endregion
233
+ //#region src/utils/source-map.ts
234
+ function isSourceMapV3(value) {
235
+ if (value === null || typeof value !== "object") return false;
236
+ const map = value;
237
+ return map.version === 3 && Array.isArray(map.sources) && Array.isArray(map.names) && typeof map.mappings === "string";
238
+ }
239
+ /**
240
+ * Parse a compiler-produced map, or `null` when there is nothing usable.
241
+ *
242
+ * A malformed map is worse than no map — Vite would chain garbage into the
243
+ * bundle's map — so anything that is not a v3 document is dropped.
244
+ */
245
+ function parseSourceMap(json) {
246
+ if (!json) return null;
247
+ let parsed;
248
+ try {
249
+ parsed = JSON.parse(json);
250
+ } catch {
251
+ return null;
252
+ }
253
+ return isSourceMapV3(parsed) ? parsed : null;
254
+ }
255
+ function countNewlines(text) {
256
+ let total = 0;
257
+ for (let index = text.indexOf("\n"); index !== -1; index = text.indexOf("\n", index + 1)) total++;
258
+ return total;
259
+ }
260
+ /**
261
+ * Insert `count` unmapped generated lines at generated line `atLine`.
262
+ *
263
+ * Returns the map unchanged when the insertion lands past the last mapped line,
264
+ * because nothing after it needs moving.
265
+ */
266
+ function shiftMappedLines(map, atLine, count) {
267
+ if (count <= 0) return map;
268
+ const groups = map.mappings.split(";");
269
+ if (atLine >= groups.length) return map;
270
+ const shifted = [
271
+ ...groups.slice(0, atLine),
272
+ ...Array(count).fill(""),
273
+ ...groups.slice(atLine)
274
+ ];
275
+ return {
276
+ ...map,
277
+ mappings: shifted.join(";")
278
+ };
279
+ }
280
+ /**
281
+ * A module's code and the map that describes it, edited together.
282
+ *
283
+ * Every write goes through {@link edit}, so the map is corrected in the same
284
+ * step that changes the code and the two cannot drift.
285
+ */
286
+ var MappedModule = class {
287
+ code;
288
+ map;
289
+ constructor(code, map) {
290
+ this.code = code;
291
+ this.map = map;
292
+ }
293
+ /** Replace the module with `next`, realigning the map to the new line layout. */
294
+ edit(next) {
295
+ const previous = this.code;
296
+ this.code = next;
297
+ if (this.map === null || next === previous) return;
298
+ const limit = Math.min(previous.length, next.length);
299
+ let prefix = 0;
300
+ while (prefix < limit && previous.charCodeAt(prefix) === next.charCodeAt(prefix)) prefix++;
301
+ let suffix = 0;
302
+ while (suffix < limit - prefix && previous.charCodeAt(previous.length - 1 - suffix) === next.charCodeAt(next.length - 1 - suffix)) suffix++;
303
+ const removed = previous.slice(prefix, previous.length - suffix);
304
+ const addedLines = countNewlines(next.slice(prefix, next.length - suffix)) - countNewlines(removed);
305
+ if (addedLines === 0) return;
306
+ if (addedLines < 0) {
307
+ this.map = null;
308
+ return;
309
+ }
310
+ const editLine = countNewlines(previous.slice(0, prefix));
311
+ const startsAtLineStart = prefix === 0 || previous.charCodeAt(prefix - 1) === 10;
312
+ this.map = shiftMappedLines(this.map, startsAtLineStart ? editLine : editLine + 1, addedLines);
313
+ }
314
+ };
315
+ //#endregion
233
316
  //#region src/utils/css.ts
234
317
  function scopeCssForPipeline(css, scopeId) {
235
318
  return scopeViteCssForPipeline(css, scopeId);
@@ -433,29 +516,40 @@ function embedsInlineCss(compiled, options) {
433
516
  return !usesStyleImports(compiled, options) && !options.ssr && !!compiled.css && !(options.isProduction && !!options.extractCss);
434
517
  }
435
518
  function generateOutput(compiled, options) {
519
+ return generateOutputWithMap(compiled, options).code;
520
+ }
521
+ /**
522
+ * `generateOutput` plus the source map that describes the module it returns.
523
+ *
524
+ * The compiler's map (`compiled.map`) describes `compiled.code`; every rewrite
525
+ * below goes through {@link MappedModule}, which realigns the map to the lines
526
+ * it inserts, so the returned map describes the returned code (#3399). `map` is
527
+ * `null` when the compiler produced none.
528
+ */
529
+ function generateOutputWithMap(compiled, options) {
436
530
  const { isProduction, isDev, ssr, hmrUpdateType, extractCss, filePath } = options;
437
- let output = compiled.code;
438
- const moduleInfo = analyzeModuleOutput(output);
531
+ const emitted = new MappedModule(compiled.code, parseSourceMap(compiled.map));
532
+ const moduleInfo = compiled.moduleShape ?? analyzeModuleOutput(emitted.code);
439
533
  const hasExportDefault = moduleInfo.hasDefaultExport;
440
534
  const hasNamedRenderExport = moduleInfo.hasNamedRenderExport;
441
535
  const hasNamedSsrRenderExport = moduleInfo.hasNamedSsrRenderExport;
442
536
  const hasSfcMainDefined = moduleInfo.hasSfcMainDefined;
443
537
  if (hasExportDefault && !hasSfcMainDefined) {
444
- output = rewriteDefaultExportToSfcMain(output, moduleInfo);
445
- if (compiled.hasScoped && compiled.scopeId) output += `\n_sfc_main.__scopeId = "data-v-${compiled.scopeId}";`;
446
- output += "\nexport default _sfc_main;";
538
+ emitted.edit(rewriteDefaultExportToSfcMain(emitted.code, moduleInfo));
539
+ if (compiled.hasScoped && compiled.scopeId) emitted.edit(`${emitted.code}\n_sfc_main.__scopeId = "data-v-${compiled.scopeId}";`);
540
+ emitted.edit(`${emitted.code}\nexport default _sfc_main;`);
447
541
  } else if (hasExportDefault && hasSfcMainDefined) {
448
- if (compiled.hasScoped && compiled.scopeId) output = insertBeforeSfcMainDefaultExport(output, `_sfc_main.__scopeId = "data-v-${compiled.scopeId}";`, { moduleInfo });
542
+ if (compiled.hasScoped && compiled.scopeId) emitted.edit(insertBeforeSfcMainDefaultExport(emitted.code, `_sfc_main.__scopeId = "data-v-${compiled.scopeId}";`, { moduleInfo }));
449
543
  } else if (!hasExportDefault && !hasSfcMainDefined && hasNamedRenderExport) {
450
- output += "\nconst _sfc_main = {};";
451
- if (compiled.hasScoped && compiled.scopeId) output += `\n_sfc_main.__scopeId = "data-v-${compiled.scopeId}";`;
452
- output += "\n_sfc_main.render = render;";
453
- output += "\nexport default _sfc_main;";
544
+ emitted.edit(`${emitted.code}\nconst _sfc_main = {};`);
545
+ if (compiled.hasScoped && compiled.scopeId) emitted.edit(`${emitted.code}\n_sfc_main.__scopeId = "data-v-${compiled.scopeId}";`);
546
+ emitted.edit(`${emitted.code}\n_sfc_main.render = render;`);
547
+ emitted.edit(`${emitted.code}\nexport default _sfc_main;`);
454
548
  } else if (!hasExportDefault && !hasSfcMainDefined && hasNamedSsrRenderExport) {
455
- output += "\nconst _sfc_main = {};";
456
- if (compiled.hasScoped && compiled.scopeId) output += `\n_sfc_main.__scopeId = "data-v-${compiled.scopeId}";`;
457
- output += "\n_sfc_main.ssrRender = ssrRender;";
458
- output += "\nexport default _sfc_main;";
549
+ emitted.edit(`${emitted.code}\nconst _sfc_main = {};`);
550
+ if (compiled.hasScoped && compiled.scopeId) emitted.edit(`${emitted.code}\n_sfc_main.__scopeId = "data-v-${compiled.scopeId}";`);
551
+ emitted.edit(`${emitted.code}\n_sfc_main.ssrRender = ssrRender;`);
552
+ emitted.edit(`${emitted.code}\nexport default _sfc_main;`);
459
553
  }
460
554
  if (usesStyleImports(compiled, options)) {
461
555
  const styleImports = [];
@@ -479,7 +573,7 @@ function generateOutput(compiled, options) {
479
573
  }
480
574
  }
481
575
  const allImports = [...styleImports, ...cssModuleImports].join("\n");
482
- if (allImports) output = insertAfterStaticImports(output, allImports);
576
+ if (allImports) emitted.edit(insertAfterStaticImports(emitted.code, allImports));
483
577
  if (cssModuleImports.length > 0) {
484
578
  const moduleBindings = [];
485
579
  for (const block of compiled.styles) if (isCssModule(block)) {
@@ -490,14 +584,17 @@ function generateOutput(compiled, options) {
490
584
  });
491
585
  }
492
586
  const cssModuleSetup = moduleBindings.map((m) => `_sfc_main.__cssModules = _sfc_main.__cssModules || {};\n_sfc_main.__cssModules[${JSON.stringify(m.name)}] = ${m.bindingName};`).join("\n");
493
- output = insertBeforeSfcMainDefaultExport(output, cssModuleSetup, { normalizeSemicolon: true });
587
+ emitted.edit(insertBeforeSfcMainDefaultExport(emitted.code, cssModuleSetup, { normalizeSemicolon: true }));
494
588
  }
495
- } else if (!ssr && compiled.css && !(isProduction && extractCss)) output = prependInlineStyleInjection(output, compiled.css, compiled.scopeId);
589
+ } else if (!ssr && compiled.css && !(isProduction && extractCss)) emitted.edit(prependInlineStyleInjection(emitted.code, compiled.css, compiled.scopeId));
496
590
  if (!isProduction && isDev && hasExportDefault) {
497
- const effectiveHmrUpdateType = hmrUpdateType === "template-only" && !supportsTemplateOnlyHmr(output) ? "full-reload" : hmrUpdateType ?? "full-reload";
498
- output += generateHmrCode(compiled.scopeId, effectiveHmrUpdateType);
591
+ const effectiveHmrUpdateType = hmrUpdateType === "template-only" && !supportsTemplateOnlyHmr(emitted.code) ? "full-reload" : hmrUpdateType ?? "full-reload";
592
+ emitted.edit(`${emitted.code}${generateHmrCode(compiled.scopeId, effectiveHmrUpdateType)}`);
499
593
  }
500
- return output;
594
+ return {
595
+ code: emitted.code,
596
+ map: emitted.map
597
+ };
501
598
  }
502
599
  const RESOLVED_CSS_MODULE = "\0vize:all-styles.css";
503
600
  /** Create a virtual module ID from a real .vue file path */
@@ -651,7 +748,7 @@ function getEnvironmentCache(state, ssr) {
651
748
  }
652
749
  function getCompileOptionsForRequest(state, ssr) {
653
750
  const options = {
654
- sourceMap: state.mergedOptions?.sourceMap ?? !state.isProduction,
751
+ sourceMap: state.mergedOptions?.sourceMap ?? (!state.isProduction || !!state.viteBuildSourcemap),
655
752
  ssr,
656
753
  vapor: !ssr && (state.mergedOptions?.vapor ?? false),
657
754
  customRenderer: state.mergedOptions?.customRenderer ?? false,
@@ -687,6 +784,84 @@ function clearBuildCaches(state) {
687
784
  state.viteResolveCache?.clear();
688
785
  }
689
786
  //#endregion
787
+ //#region src/plugin/compiled-module-cache.ts
788
+ /**
789
+ * Compiled-module caches carrying a reverse index from a `src`-imported
790
+ * dependency to the SFCs that pulled it in.
791
+ *
792
+ * Every hot update has to answer "which SFCs own this changed file?" before it
793
+ * can do anything else, and that answer used to come from a full scan of both
794
+ * caches with a `path.resolve` per dependency per cached file. HMR latency then
795
+ * grew with the number of components in the project, on the interactive path,
796
+ * for every save — including saves of ordinary `.vue` files, because the scan
797
+ * runs before the `.vue` fast path.
798
+ *
799
+ * The index is maintained by overriding `set`/`delete`/`clear` rather than by a
800
+ * second structure updated at each call site. `state.cache` is handed to
801
+ * `compileFile` and `compileBatch`, and is also mutated directly from
802
+ * `precompile-run.ts`, `hmr.ts` and `state.ts`; a structure kept in sync by hand
803
+ * across those would drift the first time a new writer appeared. Subclassing
804
+ * puts the bookkeeping where the mutation is.
805
+ *
806
+ * The keys are `path.resolve`d exactly as the previous scan resolved them, so a
807
+ * dependency recorded as a relative path indexes and looks up identically.
808
+ */
809
+ var CompiledModuleCache = class extends Map {
810
+ #ownersByDependency = /* @__PURE__ */ new Map();
811
+ /**
812
+ * Deliberately takes no entries: `Map`'s constructor would call the
813
+ * overridden `set` from inside `super()`, before `#ownersByDependency` exists.
814
+ */
815
+ constructor() {
816
+ super();
817
+ }
818
+ set(file, compiled) {
819
+ this.#unindex(file);
820
+ super.set(file, compiled);
821
+ for (const dependency of compiled.dependencies ?? []) {
822
+ const key = path.resolve(dependency);
823
+ const owners = this.#ownersByDependency.get(key);
824
+ if (owners) owners.add(file);
825
+ else this.#ownersByDependency.set(key, new Set([file]));
826
+ }
827
+ return this;
828
+ }
829
+ delete(file) {
830
+ this.#unindex(file);
831
+ return super.delete(file);
832
+ }
833
+ clear() {
834
+ this.#ownersByDependency.clear();
835
+ super.clear();
836
+ }
837
+ /** The cached SFCs that `src`-import `resolvedDependency`. */
838
+ ownersOf(resolvedDependency) {
839
+ const owners = this.#ownersByDependency.get(resolvedDependency);
840
+ return owners ? [...owners] : [];
841
+ }
842
+ #unindex(file) {
843
+ for (const dependency of super.get(file)?.dependencies ?? []) {
844
+ const key = path.resolve(dependency);
845
+ const owners = this.#ownersByDependency.get(key);
846
+ if (!owners) continue;
847
+ owners.delete(file);
848
+ if (owners.size === 0) this.#ownersByDependency.delete(key);
849
+ }
850
+ }
851
+ };
852
+ /**
853
+ * Owners of `resolvedDependency` in one cache.
854
+ *
855
+ * Plain `Map`s — the hand-built states in unit tests — keep the original linear
856
+ * scan, so an unindexed cache answers exactly what the indexed one does.
857
+ */
858
+ function ownersOfDependency(cache, resolvedDependency) {
859
+ if (cache instanceof CompiledModuleCache) return cache.ownersOf(resolvedDependency);
860
+ const owners = [];
861
+ for (const [file, compiled] of cache) if (compiled.dependencies?.some((dependency) => path.resolve(dependency) === resolvedDependency)) owners.push(file);
862
+ return owners;
863
+ }
864
+ //#endregion
690
865
  //#region src/compile-options.ts
691
866
  function buildCompileFileOptions(filePath, options) {
692
867
  return {
@@ -717,6 +892,7 @@ function buildCompileBatchOptions(options) {
717
892
  includeStyles: true,
718
893
  includeMacroArtifacts: true,
719
894
  includeHashes: true,
895
+ includeSourceMap: options.sourceMap,
720
896
  ...options.mode === void 0 ? {} : { mode: options.mode },
721
897
  ...options.templateSyntax === void 0 ? {} : { templateSyntax: options.templateSyntax },
722
898
  ...options.runtimeModuleName === void 0 ? {} : { runtimeModuleName: options.runtimeModuleName },
@@ -823,6 +999,7 @@ function compileFile(filePath, cache, options, source, diagnostics) {
823
999
  });
824
1000
  const compiled = {
825
1001
  code: result.code,
1002
+ ...result.map ? { map: result.map } : {},
826
1003
  css: result.css,
827
1004
  scopeId,
828
1005
  hasScoped: result.hasScoped,
@@ -886,6 +1063,7 @@ function compileBatch(files, cache, options) {
886
1063
  for (const fileResult of result.results) {
887
1064
  if (fileResult.errors.length === 0) cache.set(fileResult.path, {
888
1065
  code: fileResult.code,
1066
+ ...fileResult.map ? { map: fileResult.map } : {},
889
1067
  css: fileResult.css,
890
1068
  scopeId: fileResult.scopeId,
891
1069
  hasScoped: fileResult.hasScoped,
@@ -961,7 +1139,7 @@ function resolveCompilerIdentity() {
961
1139
  */
962
1140
  function computePrecompileCacheKey(compileOptions) {
963
1141
  const material = stableStringify({
964
- format: 2,
1142
+ format: 3,
965
1143
  compiler: resolveCompilerIdentity(),
966
1144
  options: compileOptions
967
1145
  });
@@ -1080,7 +1258,7 @@ function encodePrecompileManifest(options) {
1080
1258
  const indexBody = compressBody(Buffer.from(JSON.stringify(index), "utf8"));
1081
1259
  const payloadBody = compressBody(Buffer.concat(records));
1082
1260
  const header = Buffer.from(JSON.stringify({
1083
- format: 2,
1261
+ format: 3,
1084
1262
  key,
1085
1263
  codec: hasZstd ? "zstd" : "gzip",
1086
1264
  index: indexBody.length,
@@ -1156,7 +1334,7 @@ function decodePrecompileManifest(bytes, options) {
1156
1334
  return reject("unparsable header");
1157
1335
  }
1158
1336
  if (typeof header !== "object" || header === null || Array.isArray(header)) return reject("unrecognized header");
1159
- if (header.format !== 2 || header.key !== key) return reject("foreign format or key");
1337
+ if (header.format !== 3 || header.key !== key) return reject("foreign format or key");
1160
1338
  if (!isByteLength(header.index) || !isByteLength(header.payload)) return reject("unrecognized body lengths");
1161
1339
  const indexStart = headerEnd + 1;
1162
1340
  const payloadStart = indexStart + header.index;
@@ -1372,6 +1550,7 @@ function writeManifest(file, container, onDiagnostic) {
1372
1550
  */
1373
1551
  function resolvePrecompileBatchOptions(state) {
1374
1552
  return {
1553
+ sourceMap: getCompileOptionsForRequest(state, false).sourceMap,
1375
1554
  ssr: false,
1376
1555
  vapor: state.mergedOptions.vapor ?? false,
1377
1556
  mode: state.mergedOptions.mode,
@@ -2386,12 +2565,15 @@ function loadCompiledSfcModule(state, realPath, isSsr, currentBase, loadOptions)
2386
2565
  ...compiled,
2387
2566
  css: resolveCssImports(compiled.css, realPath, state.cssAliasRules, state.server !== null, currentBase)
2388
2567
  };
2389
- const generatedOutput = generateOutput(compiled, outputOptions);
2390
- const normalizedOutput = rewriteImportMetaGlobBase(rewriteStaticAssetUrls(rewriteDynamicTemplateImports(isSsr ? normalizeVueServerRendererImport(generatedOutput) : generatedOutput, state.dynamicImportAliasRules), state.dynamicImportAliasRules), realPath, state.root);
2568
+ const emitted = generateOutputWithMap(compiled, outputOptions);
2569
+ const rewritten = new MappedModule(isSsr ? normalizeVueServerRendererImport(emitted.code) : emitted.code, emitted.map);
2570
+ rewritten.edit(rewriteDynamicTemplateImports(rewritten.code, state.dynamicImportAliasRules));
2571
+ rewritten.edit(rewriteStaticAssetUrls(rewritten.code, state.dynamicImportAliasRules));
2572
+ rewritten.edit(rewriteImportMetaGlobBase(rewritten.code, realPath, state.root));
2391
2573
  if (!loadOptions?.ssr) state.pendingHmrUpdateTypes.delete(realPath);
2392
2574
  return {
2393
- code: normalizedOutput,
2394
- map: null
2575
+ code: rewritten.code,
2576
+ map: rewritten.map
2395
2577
  };
2396
2578
  }
2397
2579
  function loadDefinePageArtifact(state, realPath, ssr) {
@@ -2539,10 +2721,20 @@ async function transformHook(state, code, id, options) {
2539
2721
  //#region src/plugin/hmr.ts
2540
2722
  const VIZE_COMPONENTS_CSS_BASENAME = "vize-components.css";
2541
2723
  const VIZE_COMPONENTS_CSS_FILE = `assets/${VIZE_COMPONENTS_CSS_BASENAME}`;
2724
+ /**
2725
+ * The cached SFCs that pulled `dependencyFile` in through
2726
+ * `<script src>` / `<template src>` / `<style src>`.
2727
+ *
2728
+ * This runs as the first statement of every hot update, before the `.vue` fast
2729
+ * path, so editing an ordinary SFC pays for it too. It used to walk both caches
2730
+ * end to end with a `path.resolve` per dependency, which made HMR latency grow
2731
+ * with the number of components in the project; the caches now carry a reverse
2732
+ * index that answers it in constant time. See `compiled-module-cache.ts`.
2733
+ */
2542
2734
  function getVueFilesDependingOn(state, dependencyFile) {
2543
2735
  const normalizedDependency = path.resolve(dependencyFile);
2544
2736
  const owners = /* @__PURE__ */ new Set();
2545
- for (const cache of [state.cache, state.ssrCache]) for (const [vueFile, compiled] of cache) if (compiled.dependencies?.some((dependency) => path.resolve(dependency) === normalizedDependency)) owners.add(vueFile);
2737
+ for (const cache of [state.cache, state.ssrCache]) for (const vueFile of ownersOfDependency(cache, normalizedDependency)) owners.add(vueFile);
2546
2738
  return [...owners];
2547
2739
  }
2548
2740
  function unique(values) {
@@ -3248,13 +3440,14 @@ function resolveCompatibilityOptions(options, compilerConfig = {}) {
3248
3440
  function vize(options = {}) {
3249
3441
  if (isLegacyVueCompatibilityMode(options)) return [createLegacyVueCompatibilityPlugin(options)];
3250
3442
  const state = {
3251
- cache: /* @__PURE__ */ new Map(),
3252
- ssrCache: /* @__PURE__ */ new Map(),
3443
+ cache: new CompiledModuleCache(),
3444
+ ssrCache: new CompiledModuleCache(),
3253
3445
  collectedCss: /* @__PURE__ */ new Map(),
3254
3446
  precompileMetadata: /* @__PURE__ */ new Map(),
3255
3447
  pendingHmrUpdateTypes: /* @__PURE__ */ new Map(),
3256
3448
  viteResolveCache: /* @__PURE__ */ new Map(),
3257
3449
  isProduction: false,
3450
+ viteBuildSourcemap: false,
3258
3451
  root: "",
3259
3452
  clientViteBase: "/",
3260
3453
  serverViteBase: "/",
@@ -3293,6 +3486,7 @@ function vize(options = {}) {
3293
3486
  async configResolved(resolvedConfig) {
3294
3487
  state.root = options.root ?? resolvedConfig.root;
3295
3488
  state.isProduction = options.isProduction ?? resolvedConfig.isProduction;
3489
+ state.viteBuildSourcemap = !!resolvedConfig.build?.sourcemap;
3296
3490
  const isSsrBuild = !!resolvedConfig.build?.ssr;
3297
3491
  const currentBase = resolvedConfig.command === "serve" ? options.devUrlBase ?? resolvedConfig.base ?? "/" : resolvedConfig.base ?? "/";
3298
3492
  if (isSsrBuild) state.serverViteBase = currentBase;
@@ -1,4 +1,4 @@
1
- import { c as ResolvedVizeConfig } from "../types-x-lq08Y8.mjs";
1
+ import { c as ResolvedVizeConfig } from "../types-Cm3dJq25.mjs";
2
2
  import { ResolvedConfig } from "vite";
3
3
 
4
4
  //#region src/internal/config-bridge.d.ts
@@ -660,6 +660,28 @@ interface ExperimentalPluginOptions extends ExperimentalCompileFlags {
660
660
  experimentals?: ExperimentalOptions;
661
661
  }
662
662
  //#endregion
663
+ //#region src/utils/module-output.d.ts
664
+ type ModuleOutputInfo = {
665
+ hasDefaultExport: boolean;
666
+ hasSfcMainDefined: boolean;
667
+ hasNamedRenderExport: boolean;
668
+ hasNamedSsrRenderExport: boolean;
669
+ defaultExportKeywordEnd: number | null;
670
+ defaultExportStart: number | null;
671
+ /**
672
+ * End offset of the whole `export default ...` statement, or `null`.
673
+ *
674
+ * Recorded so {@link insertBeforeSfcMainDefaultExport} can reuse the caller's
675
+ * analysis instead of parsing the module a second time (#3425).
676
+ */
677
+ defaultExportEnd: number | null;
678
+ /**
679
+ * Whether the default export's declaration is exactly the `_sfc_main`
680
+ * identifier -- the only shape {@link insertBeforeSfcMainDefaultExport} acts on.
681
+ */
682
+ defaultExportIsSfcMain: boolean;
683
+ };
684
+ //#endregion
663
685
  //#region src/types.d.ts
664
686
  interface MacroArtifact {
665
687
  kind: string;
@@ -755,7 +777,10 @@ interface VizeOptions extends ExperimentalPluginOptions {
755
777
  */
756
778
  isProduction?: boolean;
757
779
  ssr?: boolean;
758
- /** Enable source map generation */
780
+ /**
781
+ * Enable source map generation.
782
+ * @default development on; production off unless Vite's `build.sourcemap` is set
783
+ */
759
784
  sourceMap?: boolean;
760
785
  /**
761
786
  * Enable Vapor mode compilation
@@ -845,6 +870,13 @@ interface StyleBlockInfo {
845
870
  }
846
871
  interface CompiledModule {
847
872
  code: string;
873
+ /**
874
+ * Source Map v3 document (JSON) describing `code`, when the compiler was
875
+ * asked for one (#3399). Absent when source maps are off, when the SFC has no
876
+ * script block, and for the rspack and unplugin builders, which do not request
877
+ * maps. Persisted with the rest of the module in the pre-compile cache.
878
+ */
879
+ map?: string;
848
880
  css?: string;
849
881
  scopeId: string;
850
882
  hasScoped: boolean;
@@ -857,6 +889,13 @@ interface CompiledModule {
857
889
  styles?: StyleBlockInfo[];
858
890
  /** Files loaded through SFC `src` imports */
859
891
  dependencies?: string[];
892
+ /**
893
+ * Module shape reported by the native compiler, so `generateOutput` need not
894
+ * re-parse the emitted module (#3425). Absent for a cache entry written before
895
+ * the field existed, and for the rspack and unplugin builders, which never set
896
+ * it — both fall back to parsing.
897
+ */
898
+ moduleShape?: ModuleOutputInfo;
860
899
  }
861
900
  //#endregion
862
901
  export { VizeVueVersion as a, ResolvedVizeConfig as c, VizeOptions as i, UserConfigExport as l, MacroArtifact as n, ConfigEnv as o, VizeCompatibilityOptions as r, LoadConfigOptions as s, CompiledModule as t, VizeConfig as u };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/vite-plugin",
3
- "version": "0.306.0",
3
+ "version": "0.312.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.306.0",
48
+ "@vizejs/native": "0.312.0",
49
49
  "oxc-parser": "0.133.0",
50
50
  "tinyglobby": "0.2.16",
51
- "vize": "0.306.0"
51
+ "vize": "0.312.0"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@types/node": "25.9.2",