@vizejs/vite-plugin 0.683.0 → 0.684.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 VizeInspectorLintPlanProvider, b as VizeConfig, c as VizeCompatibilityOptions, d as LoadConfigOptions, f as ResolvedVizeConfig, h as VueOptionsEntry, i as VizeVueFeatures, l as VizeVueVersion, m as VueOptions, n as CompiledModule, o as VizeInspectorLintPlanRequest, p as UserConfigExport, r as MacroArtifact, s as VizeInspectorOptions, t as VizeOptions, u as ConfigEnv } from "./types-BYtdVAwW.mjs";
1
+ import { a as VizeInspectorLintPlanProvider, b as VizeConfig, c as VizeCompatibilityOptions, d as LoadConfigOptions, f as ResolvedVizeConfig, h as VueOptionsEntry, i as VizeVueFeatures, l as VizeVueVersion, m as VueOptions, n as CompiledModule, o as VizeInspectorLintPlanRequest, p as UserConfigExport, r as MacroArtifact, s as VizeInspectorOptions, t as VizeOptions, u as ConfigEnv } from "./types-DRbVPh2U.mjs";
2
2
  import { Plugin } from "vite";
3
3
 
4
4
  //#region src/plugin/compiler-config.d.ts
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as vize } from "./plugin-D9-_kA6W.mjs";
1
+ import { t as vize } from "./plugin-cSFUkcfU.mjs";
2
2
  import { u as rewriteStaticAssetUrls } from "./vue-version-B0qUneRk.mjs";
3
3
  import { a as resolveViteConfigExport, i as resolveConfigExport, n as defineConfig, o as vizeConfigStore, r as loadConfig, t as VIZE_CONFIG_FILE_ENV } from "./config-LlMZcDZI.mjs";
4
4
  //#region src/index.ts
@@ -1,4 +1,4 @@
1
- import { f as ResolvedVizeConfig } from "../types-BYtdVAwW.mjs";
1
+ import { f as ResolvedVizeConfig } from "../types-DRbVPh2U.mjs";
2
2
  import { ResolvedConfig } from "vite";
3
3
 
4
4
  //#region src/internal/config-bridge.d.ts
@@ -0,0 +1,2 @@
1
+ import { t as vize } from "./plugin-cSFUkcfU.mjs";
2
+ export { vize };
@@ -15,7 +15,7 @@ import * as vite from "vite";
15
15
  //#region src/hmr.ts
16
16
  function hasHmrChanges(prev, next) {
17
17
  if (!prev) return true;
18
- return hasViteHmrChanges(toHmrHashes(prev), toHmrHashes(next)) || runtimeFingerprint(prev) !== runtimeFingerprint(next) || styleFingerprint(prev) !== styleFingerprint(next);
18
+ return hasViteHmrChanges(toHmrHashes(prev), toHmrHashes(next)) || runtimeFingerprint(prev) !== runtimeFingerprint(next) || styleFingerprint(prev) !== styleFingerprint(next) || hasCustomBlockChanges(prev, next);
19
19
  }
20
20
  /**
21
21
  * Detect the type of HMR update needed based on content hash changes.
@@ -27,6 +27,7 @@ function hasHmrChanges(prev, next) {
27
27
  function detectHmrUpdateType(prev, next) {
28
28
  if (!prev) return detectViteHmrUpdateType(void 0, toHmrHashes(next));
29
29
  if (prev.scriptHash !== next.scriptHash) return "full-reload";
30
+ if (hasCustomBlockChanges(prev, next)) return "full-reload";
30
31
  if (prev.templateHash !== next.templateHash) return "template-only";
31
32
  if (prev.styleHash !== next.styleHash) return "style-only";
32
33
  if (runtimeFingerprint(prev) !== runtimeFingerprint(next)) return "full-reload";
@@ -48,6 +49,10 @@ function hasStyleChanges(prev, next) {
48
49
  if (!prev) return true;
49
50
  return prev.styleHash !== next.styleHash || styleFingerprint(prev) !== styleFingerprint(next);
50
51
  }
52
+ /** Whether custom-block content changed, including the first time blocks appear. */
53
+ function hasCustomBlockChanges(prev, next) {
54
+ return customBlockFingerprint(prev) !== customBlockFingerprint(next);
55
+ }
51
56
  function toHmrHashes(module) {
52
57
  return module ? {
53
58
  scriptHash: module.scriptHash,
@@ -78,6 +83,15 @@ function runtimeFingerprint(module) {
78
83
  dependencies: [...module.dependencies ?? []].sort()
79
84
  });
80
85
  }
86
+ function customBlockFingerprint(module) {
87
+ return JSON.stringify((module?.customBlocks ?? []).map((block) => ({
88
+ type: block.type,
89
+ content: block.content,
90
+ src: block.src ?? null,
91
+ attrs: block.attrs,
92
+ index: block.index
93
+ })));
94
+ }
81
95
  function styleFingerprint(module) {
82
96
  return JSON.stringify({
83
97
  css: module.css,
@@ -447,6 +461,97 @@ function assembleComponentOutput(compiled) {
447
461
  };
448
462
  }
449
463
  //#endregion
464
+ //#region src/custom-blocks.ts
465
+ const RESERVED_BLOCK_TYPES = new Set([
466
+ "style",
467
+ "script",
468
+ "template"
469
+ ]);
470
+ /** Map native `blockType` blocks onto the shape Vite emits and reloads. */
471
+ function normalizeCustomBlocks(blocks) {
472
+ if (!blocks) return [];
473
+ return blocks.map((block) => {
474
+ const attrs = {};
475
+ for (const attr of block.attrs ?? []) {
476
+ const value = attr.value;
477
+ attrs[attr.name] = value == null || value === "" ? true : value;
478
+ }
479
+ return {
480
+ type: block.blockType,
481
+ content: block.content,
482
+ src: block.src || null,
483
+ attrs,
484
+ index: block.index
485
+ };
486
+ });
487
+ }
488
+ /**
489
+ * Query for one custom block, without the leading `?`.
490
+ *
491
+ * `vue` is a bare flag (`vue&type=`), which is what user plugins match.
492
+ * Vite may re-serialize that empty param as `vue=&type=`; load accepts both.
493
+ * `index` is the block's position in the custom-block list. A `src` block
494
+ * carries `src=true` rather than the path. Other attributes follow, except `src`.
495
+ */
496
+ function customBlockQuery(block, index) {
497
+ const parts = [
498
+ "vue",
499
+ `type=${block.type}`,
500
+ `index=${index}`
501
+ ];
502
+ if (block.src) parts.push("src=true");
503
+ for (const [key, value] of Object.entries(block.attrs)) {
504
+ if (key === "src") continue;
505
+ parts.push(value === true ? key : `${key}=${value}`);
506
+ }
507
+ return parts.join("&");
508
+ }
509
+ function customBlockRequest(filePath, block, index) {
510
+ return `${filePath}?${customBlockQuery(block, index)}`;
511
+ }
512
+ /** Import plus call, matching the rspack custom-block wiring. */
513
+ function customBlockModuleCode(filePath, blocks) {
514
+ return blocks.map((block, index) => {
515
+ return `import block${index} from ${JSON.stringify(customBlockRequest(filePath, block, index))};\nif (typeof block${index} === 'function') block${index}(_sfc_main);`;
516
+ }).join("\n");
517
+ }
518
+ /**
519
+ * Insert `insertion` immediately before `export default _sfc_main`, so the
520
+ * call runs after `_sfc_main` exists and before importers read the export.
521
+ * Appends when that export is not a statement in this module.
522
+ */
523
+ function insertBeforeSfcMainDefaultExport(code, insertion) {
524
+ const block = insertion.endsWith("\n") ? insertion : `${insertion}\n`;
525
+ const lineStart = sfcMainDefaultExportLineStart(code);
526
+ if (lineStart < 0) return `${code}${code.endsWith("\n") ? "" : "\n"}${block}`;
527
+ return `${code.slice(0, lineStart)}${block}${code.slice(lineStart)}`;
528
+ }
529
+ function sfcMainDefaultExportLineStart(code) {
530
+ const marker = "export default _sfc_main";
531
+ let at = code.lastIndexOf(marker);
532
+ while (at >= 0) {
533
+ const lineStart = code.lastIndexOf("\n", at - 1) + 1;
534
+ if (code.slice(lineStart, at).trim() === "") return lineStart;
535
+ at = code.lastIndexOf(marker, at - 1);
536
+ }
537
+ return -1;
538
+ }
539
+ /** A Vue custom-block query: `type` is present and is not a built-in block. */
540
+ function parseCustomBlockQuery(id) {
541
+ const start = id.indexOf("?");
542
+ if (start < 0) return null;
543
+ const params = new URLSearchParams(id.slice(start + 1));
544
+ if (!params.has("vue")) return null;
545
+ const type = params.get("type");
546
+ if (!type || RESERVED_BLOCK_TYPES.has(type)) return null;
547
+ const index = Number.parseInt(params.get("index") ?? "0", 10);
548
+ if (!Number.isInteger(index) || index < 0) return null;
549
+ return {
550
+ type,
551
+ index
552
+ };
553
+ }
554
+ //#endregion
450
555
  //#region src/plugin/style-request.ts
451
556
  const STYLE_MARKER = ".__vize_style_";
452
557
  function normalizeInlineStyleModifiers(id) {
@@ -822,6 +927,7 @@ function generateOutputWithMap(compiled, options) {
822
927
  emitted.edit(`${emitted.code}\n${cssModuleSetup}`);
823
928
  }
824
929
  } else if (!ssr && compiled.css && !(isProduction && extractCss)) emitted.edit(prependInlineStyleInjection(emitted.code, compiled.css, compiled.scopeId));
930
+ if (filePath && exportsSfcMain && compiled.customBlocks?.length) emitted.edit(insertBeforeSfcMainDefaultExport(emitted.code, customBlockModuleCode(filePath, compiled.customBlocks)));
825
931
  if (!isProduction && isDev && hasExportDefault) {
826
932
  const effectiveHmrUpdateType = hmrUpdateType === "template-only" && !supportsTemplateOnlyHmr(emitted.code) ? "full-reload" : hmrUpdateType ?? "full-reload";
827
933
  emitted.edit(`${emitted.code}${generateHmrCode(compiled.scopeId, effectiveHmrUpdateType)}`);
@@ -1366,6 +1472,7 @@ function buildCompileBatchOptions(options) {
1366
1472
  experimentalStrictSlotChildren: options.experimentalStrictSlotChildren ?? false,
1367
1473
  experimentalServerScript: options.experimentalServerScript ?? false,
1368
1474
  includeStyles: true,
1475
+ includeCustomBlocks: true,
1369
1476
  includeMacroArtifacts: true,
1370
1477
  includeHashes: true,
1371
1478
  includeSourceMap: options.sourceMap,
@@ -1400,6 +1507,10 @@ var VizeSfcCompileError = class extends Error {
1400
1507
  function formatCompileErrorMessage(filePath, diagnostics) {
1401
1508
  return `[vize] Compilation failed in ${filePath}:\n${diagnostics.map((diagnostic) => ` - ${diagnostic}`).join("\n")}`;
1402
1509
  }
1510
+ function customBlockFields(blocks) {
1511
+ const customBlocks = normalizeCustomBlocks(blocks);
1512
+ return customBlocks.length > 0 ? { customBlocks } : {};
1513
+ }
1403
1514
  function normalizeStyleBlocks(styles, inlined) {
1404
1515
  if (!styles) return [];
1405
1516
  return styles.map((block) => ({
@@ -1435,6 +1546,7 @@ function compileFile(filePath, cache, options, source, diagnostics) {
1435
1546
  scriptHash: result.scriptHash,
1436
1547
  macroArtifacts: result.macroArtifacts ?? [],
1437
1548
  styles: normalizeStyleBlocks(result.styles, resolved),
1549
+ ...customBlockFields(result.customBlocks),
1438
1550
  dependencies: [...resolved.dependencies, ...result.dependencies ?? []],
1439
1551
  ...result.moduleShape ? { moduleShape: result.moduleShape } : {}
1440
1552
  };
@@ -1530,6 +1642,7 @@ function compileBatch(files, cache, options) {
1530
1642
  scriptHash: fileResult.scriptHash,
1531
1643
  macroArtifacts: fileResult.macroArtifacts ?? [],
1532
1644
  styles: normalizeStyleBlocks(fileResult.styles, inlinedByPath.get(fileResult.path)),
1645
+ ...customBlockFields(fileResult.customBlocks),
1533
1646
  dependencies: [...inlinedByPath.get(fileResult.path)?.dependencies ?? [], ...fileResult.dependencies ?? []],
1534
1647
  ...fileResult.moduleShape ? { moduleShape: fileResult.moduleShape } : {}
1535
1648
  });
@@ -3359,6 +3472,51 @@ function getVirtualStyleContent(block, options) {
3359
3472
  return transformCssVarsForPipeline(styleContent, options.scopeId, options.productionFilename);
3360
3473
  }
3361
3474
  //#endregion
3475
+ //#region src/plugin/custom-block-load.ts
3476
+ /**
3477
+ * Raw source for `?vue&type=<block>&index=N`, or `null` when `id` is not a
3478
+ * custom-block query. Style, script, and template queries stay on their own
3479
+ * paths. A `src` block reads that file and watches it.
3480
+ */
3481
+ function loadCustomBlock(state, id, options) {
3482
+ const query = parseCustomBlockQuery(id);
3483
+ if (!query) return null;
3484
+ const request = classifyVitePluginRequest(id);
3485
+ if (!request.isVueSfcPath) return null;
3486
+ const owner = vueOwnerPath(state, request.path);
3487
+ const block = getCompiledStyleSource(state, owner, !!options?.ssr)?.customBlocks?.[query.index];
3488
+ if (!block) return {
3489
+ code: "",
3490
+ map: null
3491
+ };
3492
+ if (block.src) return loadSrcBlock(state, owner, block, query.type, options?.addWatchFile);
3493
+ return {
3494
+ code: block.content,
3495
+ map: null
3496
+ };
3497
+ }
3498
+ function vueOwnerPath(state, requestPath) {
3499
+ const owner = requestPath.startsWith("/@fs/") ? requestPath.slice(4) : requestPath;
3500
+ if (owner.startsWith("/") && !fs.existsSync(owner)) {
3501
+ const projectPath = path.resolve(state.root, owner.slice(1));
3502
+ if (fs.existsSync(projectPath)) return projectPath;
3503
+ }
3504
+ return owner;
3505
+ }
3506
+ function loadSrcBlock(state, owner, block, blockType, addWatchFile) {
3507
+ const blockPath = path.resolve(path.dirname(owner), block.src ?? "");
3508
+ addWatchFile?.(blockPath);
3509
+ state.server?.watcher.add(blockPath);
3510
+ try {
3511
+ return {
3512
+ code: fs.readFileSync(blockPath, "utf8"),
3513
+ map: null
3514
+ };
3515
+ } catch {
3516
+ throw new Error(`[vize] Custom block <${blockType} src="${block.src}"> not found (resolved: ${blockPath}) in ${owner}`);
3517
+ }
3518
+ }
3519
+ //#endregion
3362
3520
  //#region src/plugin/dependency-watches.ts
3363
3521
  /**
3364
3522
  * Vite records a transform's addWatchFile calls as module imports. Compiler
@@ -3550,6 +3708,8 @@ function loadHook(state, id, loadOptions) {
3550
3708
  for (const css of state.collectedCss.values()) allCss += allCss ? `\n\n${css}` : css;
3551
3709
  return allCss;
3552
3710
  }
3711
+ const customBlock = loadCustomBlock(state, id, loadOptions);
3712
+ if (customBlock) return customBlock;
3553
3713
  const styleRequest = classifyVitePluginRequest(normalizeStyleVirtualId(id));
3554
3714
  if (styleRequest.isVueStyleQuery) {
3555
3715
  const isRootRelative = !!styleRequest.querySuffix && new URLSearchParams(styleRequest.querySuffix.slice(1)).has("vize-root-relative");
@@ -3724,6 +3884,24 @@ function invalidateModules(server, modules) {
3724
3884
  for (const module of modules) server.moduleGraph.invalidateModule(module);
3725
3885
  }
3726
3886
  //#endregion
3887
+ //#region src/plugin/custom-block-hmr.ts
3888
+ /** Module ids for one custom block, including Vite's `vue=` rewrite and `/@fs`. */
3889
+ function customBlockModuleIds(file, compiled) {
3890
+ const ids = [];
3891
+ for (const [index, block] of (compiled.customBlocks ?? []).entries()) {
3892
+ const query = customBlockQuery(block, index);
3893
+ const bare = `${file}?${query}`;
3894
+ const rewritten = `${file}?${query.replace(/^vue&/, "vue=&")}`;
3895
+ ids.push(bare, rewritten);
3896
+ if (bare.startsWith("/")) ids.push(`/@fs${bare}`, `/@fs${rewritten}`);
3897
+ }
3898
+ return ids;
3899
+ }
3900
+ /** Custom-block modules whose raw content a dev edit must send through again. */
3901
+ async function collectCustomBlockModules(server, file, compiled) {
3902
+ return collectModulesByFile(server, customBlockModuleIds(file, compiled));
3903
+ }
3904
+ //#endregion
3727
3905
  //#region src/plugin/hmr.ts
3728
3906
  const VIZE_COMPONENTS_CSS_BASENAME = "vize-components.css";
3729
3907
  const VIZE_COMPONENTS_CSS_FILE = `assets/${VIZE_COMPONENTS_CSS_BASENAME}`;
@@ -3839,12 +4017,18 @@ async function handleHotUpdateHook(state, ctx, options = {}) {
3839
4017
  if (modules.size > 0) {
3840
4018
  state.pendingHmrUpdateTypes.set(file, updateType);
3841
4019
  invalidateModules(server, modules);
4020
+ const affected = new Set(modules);
3842
4021
  if (newCompiled.styles?.length && hasStyleChanges(prevCompiled, newCompiled)) {
3843
4022
  const styleModules = await collectStyleModules(server, file, newCompiled);
3844
4023
  invalidateModules(server, styleModules);
3845
- return [...new Set([...modules, ...styleModules])];
4024
+ for (const module of styleModules) affected.add(module);
4025
+ }
4026
+ if (hasCustomBlockChanges(prevCompiled, newCompiled)) {
4027
+ const blockModules = await collectCustomBlockModules(server, file, newCompiled);
4028
+ invalidateModules(server, blockModules);
4029
+ for (const module of blockModules) affected.add(module);
3846
4030
  }
3847
- return [...modules];
4031
+ return [...affected];
3848
4032
  }
3849
4033
  state.pendingHmrUpdateTypes.delete(file);
3850
4034
  } catch (e) {
@@ -5024,7 +5208,10 @@ function vize(options = {}, compilerDefaults = {}, hostContext) {
5024
5208
  });
5025
5209
  },
5026
5210
  load(id, loadOptions) {
5027
- return loadHook(state, id, { ssr: resolveHookSsr(this, loadOptions) });
5211
+ return loadHook(state, id, {
5212
+ ssr: resolveHookSsr(this, loadOptions),
5213
+ addWatchFile: (file) => this.addWatchFile(file)
5214
+ });
5028
5215
  },
5029
5216
  async transform(code, id, transformOptions) {
5030
5217
  return transformHook(state, code, id, {
@@ -1164,6 +1164,15 @@ interface MacroArtifact {
1164
1164
  start: number;
1165
1165
  end: number;
1166
1166
  }
1167
+ /** Custom block handed to Vite. `type` is the native `blockType`. */
1168
+ interface CustomBlockInfo {
1169
+ type: string;
1170
+ content: string;
1171
+ src?: string | null;
1172
+ /** Non-boolean attributes keep their value; boolean attributes are `true`. */
1173
+ attrs: Record<string, string | true>;
1174
+ index: number;
1175
+ }
1167
1176
  interface StyleBlockInfo {
1168
1177
  /** Raw style content (uncompiled for preprocessor langs) */
1169
1178
  content: string;
@@ -1204,6 +1213,11 @@ interface CompiledModule {
1204
1213
  macroArtifacts?: MacroArtifact[];
1205
1214
  /** Per-block style metadata extracted from the source SFC */
1206
1215
  styles?: StyleBlockInfo[];
1216
+ /**
1217
+ * Custom blocks. Absent on old cache entries and hand-built fixtures;
1218
+ * absence means the module emits no custom-block imports.
1219
+ */
1220
+ customBlocks?: CustomBlockInfo[];
1207
1221
  /** Files loaded through SFC `src` imports */
1208
1222
  dependencies?: string[];
1209
1223
  /**
@@ -1,4 +1,4 @@
1
- import { _ as FormatterConfig, g as CompilerConfig, h as VueOptionsEntry, m as VueOptions, p as UserConfigExport, t as VizeOptions, v as LinterConfig, y as TypeCheckerConfig } from "./types-BYtdVAwW.mjs";
1
+ import { _ as FormatterConfig, g as CompilerConfig, h as VueOptionsEntry, m as VueOptions, p as UserConfigExport, t as VizeOptions, v as LinterConfig, y as TypeCheckerConfig } from "./types-DRbVPh2U.mjs";
2
2
  import { ConfigEnv, UserConfig, defineConfig as defineConfig$1 } from "vite-plus";
3
3
 
4
4
  //#region src/vite-plus/types.d.ts
@@ -400,7 +400,7 @@ function defineConfig(config = {}, integration = {}) {
400
400
  const legacy = compiler !== false && (await import("./vue-version-DL5NF2G-.mjs")).isLegacyVueCompatibilityMode(compiler);
401
401
  const plugins = compiler === false || legacy ? [...vp.plugins ?? []] : await withoutVueCompiler(vp.plugins ?? []);
402
402
  if (compiler !== false) {
403
- const { vize } = await import("./plugin-CjXV_gJm.mjs");
403
+ const { vize } = await import("./plugin-Dk8r3C7V.mjs");
404
404
  plugins.push(vize({
405
405
  ...plugin,
406
406
  configMode: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/vite-plugin",
3
- "version": "0.683.0",
3
+ "version": "0.684.0",
4
4
  "description": "High-performance native Vite plugin for Vue SFC compilation powered by Vize",
5
5
  "keywords": [
6
6
  "compiler",
@@ -51,13 +51,13 @@
51
51
  "access": "public"
52
52
  },
53
53
  "dependencies": {
54
- "@vizejs/native": "0.683.0",
55
- "@vizejs/unplugin": "0.683.0",
54
+ "@vizejs/native": "0.684.0",
55
+ "@vizejs/unplugin": "0.684.0",
56
56
  "jsonc-parser": "^3.3.1",
57
57
  "oxc-parser": "0.144.0",
58
58
  "picomatch": "4.0.5",
59
59
  "tinyglobby": "0.2.17",
60
- "vize": "0.683.0"
60
+ "vize": "0.684.0"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/node": "25.9.2",
@@ -1,2 +0,0 @@
1
- import { t as vize } from "./plugin-D9-_kA6W.mjs";
2
- export { vize };