@vizejs/vite-plugin 0.670.0 → 0.672.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-mem20MPI.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-ChOAu19s.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-DZ3byUmi.mjs";
1
+ import { t as vize } from "./plugin-NwXGnmXs.mjs";
2
2
  import { u as rewriteStaticAssetUrls } from "./vue-version-BFh0eI6J.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-mem20MPI.mjs";
1
+ import { f as ResolvedVizeConfig } from "../types-ChOAu19s.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-NwXGnmXs.mjs";
2
+ export { vize };
@@ -88,10 +88,34 @@ function styleFingerprint(module) {
88
88
  });
89
89
  }
90
90
  //#endregion
91
+ //#region ../shared/native-shape.ts
92
+ function utf16Offset(bytes, offset) {
93
+ if (offset == null || offset < 0 || !Number.isInteger(offset)) throw new Error("[vize] Missing native component export geometry.");
94
+ if (offset > bytes.length || offset < bytes.length && (bytes[offset] & 192) === 128) throw new Error("[vize] Invalid native component export geometry.");
95
+ return bytes.subarray(0, offset).toString("utf8").length;
96
+ }
97
+ /**
98
+ * Rewrite `export default X` to `const name = X` at the span the native
99
+ * compiler reported, converting its UTF-8 byte offsets against `module.code`.
100
+ * The span must still spell `export default` there, so a UTF-16 index or a span
101
+ * made stale by an earlier edit throws instead of corrupting the module.
102
+ */
103
+ function bindDefaultExport(module, shape, name) {
104
+ const bytes = Buffer.from(module.code);
105
+ const start = utf16Offset(bytes, shape.defaultExportStart);
106
+ const end = utf16Offset(bytes, shape.defaultExportKeywordEnd);
107
+ if (!/^export\s+default$/.test(module.code.slice(start, end))) throw new Error("[vize] Native component export geometry does not describe this module.");
108
+ module.replace(start, end, `const ${name} =`);
109
+ }
110
+ //#endregion
91
111
  //#region src/utils/module-output.ts
92
112
  const OUTPUT_PARSE_ID = "vize-output.tsx";
93
113
  const SFC_MAIN_NAME = "_sfc_main";
94
114
  const EXPORT_DEFAULT = "export default";
115
+ /** oxc and string indices count UTF-16 units; the native shape counts UTF-8 bytes. */
116
+ function byteOffset(code, index) {
117
+ return index == null ? null : Buffer.byteLength(code.slice(0, index));
118
+ }
95
119
  function isNode(value) {
96
120
  return value != null && typeof value === "object" && typeof value.type === "string";
97
121
  }
@@ -163,8 +187,8 @@ function analyzeFastDefaultOutput(code) {
163
187
  hasSfcMainDefined: false,
164
188
  hasNamedRenderExport: false,
165
189
  hasNamedSsrRenderExport: false,
166
- defaultExportStart,
167
- defaultExportKeywordEnd: defaultExportStart + 14,
190
+ defaultExportStart: byteOffset(code, defaultExportStart),
191
+ defaultExportKeywordEnd: byteOffset(code, defaultExportStart + 14),
168
192
  defaultExportEnd: null,
169
193
  defaultExportIsSfcMain: false
170
194
  };
@@ -191,36 +215,12 @@ function analyzeModuleOutput(code) {
191
215
  }),
192
216
  hasNamedRenderExport: exportedNames.includes("render"),
193
217
  hasNamedSsrRenderExport: exportedNames.includes("ssrRender"),
194
- defaultExportKeywordEnd,
195
- defaultExportStart,
196
- defaultExportEnd: getNodeEnd(defaultExport),
218
+ defaultExportKeywordEnd: byteOffset(code, defaultExportKeywordEnd),
219
+ defaultExportStart: byteOffset(code, defaultExportStart),
220
+ defaultExportEnd: byteOffset(code, getNodeEnd(defaultExport)),
197
221
  defaultExportIsSfcMain: isSfcMainDefaultExport(defaultExport)
198
222
  };
199
223
  }
200
- function rewriteDefaultExportToSfcMain(code, moduleInfo = {
201
- defaultExportKeywordEnd: null,
202
- defaultExportStart: null
203
- }) {
204
- let exportStart = moduleInfo.defaultExportStart;
205
- let keywordEnd = moduleInfo.defaultExportKeywordEnd;
206
- if (exportStart == null || keywordEnd == null) {
207
- const defaultExport = findDefaultExport(parseProgram(code));
208
- exportStart = getNodeStart(defaultExport);
209
- keywordEnd = defaultExport ? getExportDefaultKeywordEnd(code, defaultExport) : null;
210
- }
211
- if (exportStart == null || keywordEnd == null) return code;
212
- return `${code.slice(0, exportStart)}const ${SFC_MAIN_NAME} =${code.slice(keywordEnd)}`;
213
- }
214
- /**
215
- * Insert `insertion` before `export default _sfc_main`. `moduleInfo` must
216
- * describe `code` exactly (offsets are used verbatim), so the module is never
217
- * parsed again (#3425).
218
- */
219
- function insertBeforeSfcMainDefaultExport(code, insertion, moduleInfo) {
220
- const exportStart = moduleInfo.defaultExportStart;
221
- if (!moduleInfo.defaultExportIsSfcMain || exportStart == null) return code;
222
- return `${code.slice(0, exportStart)}${insertion}\n${code.slice(exportStart)}`;
223
- }
224
224
  //#endregion
225
225
  //#region ../shared/source-map.ts
226
226
  function isSourceMapV3(value) {
@@ -297,9 +297,9 @@ function prependMappedJsxCode(code, mapJson, prefix) {
297
297
  *
298
298
  * The native compiler returns a map for the module it emitted. `generateOutput`
299
299
  * then rewrites that module: it prepends a `<style>` injection, splices style
300
- * imports in after the last static import, inserts CSS-module wiring before the
301
- * default export, rewrites `export default` to `const _sfc_main =`, and appends
302
- * `__scopeId`/HMR code. All of those are whole-line insertions or same-line
300
+ * imports in after the last static import, rewrites `export default` to
301
+ * `const _sfc_main =`, and appends `__scopeId`, CSS-module wiring and HMR
302
+ * code. All of those are whole-line insertions or same-line
303
303
  * substitutions, which is exactly the class of edit a v3 `mappings` string can
304
304
  * absorb without being decoded:
305
305
  *
@@ -356,6 +356,10 @@ var MappedModule = class {
356
356
  const startsAtLineStart = prefix === 0 || previous.charCodeAt(prefix - 1) === 10;
357
357
  this.map = shiftMappedLines(this.map, startsAtLineStart ? editLine : editLine + 1, addedLines);
358
358
  }
359
+ /** Replace `code[start, end)`, in UTF-16 indices. */
360
+ replace(start, end, text) {
361
+ this.edit(`${this.code.slice(0, start)}${text}${this.code.slice(end)}`);
362
+ }
359
363
  };
360
364
  //#endregion
361
365
  //#region src/utils/component-output.ts
@@ -369,12 +373,12 @@ function assembleComponentOutput(compiled) {
369
373
  const hasSfcMainDefined = moduleInfo.hasSfcMainDefined;
370
374
  let exportsSfcMain = true;
371
375
  if (hasExportDefault && !hasSfcMainDefined) {
372
- emitted.edit(rewriteDefaultExportToSfcMain(emitted.code, moduleInfo));
376
+ bindDefaultExport(emitted, moduleInfo, "_sfc_main");
373
377
  if (compiled.hasScoped && compiled.scopeId) emitted.edit(`${emitted.code}\n_sfc_main.__scopeId = "data-v-${compiled.scopeId}";`);
374
378
  emitted.edit(`${emitted.code}\nexport default _sfc_main;`);
375
379
  } else if (hasExportDefault && hasSfcMainDefined) {
376
380
  exportsSfcMain = moduleInfo.defaultExportIsSfcMain;
377
- if (compiled.hasScoped && compiled.scopeId) emitted.edit(insertBeforeSfcMainDefaultExport(emitted.code, `_sfc_main.__scopeId = "data-v-${compiled.scopeId}";`, moduleInfo));
381
+ if (exportsSfcMain && compiled.hasScoped && compiled.scopeId) emitted.edit(`${emitted.code}\n_sfc_main.__scopeId = "data-v-${compiled.scopeId}";`);
378
382
  } else if (!hasExportDefault && !hasSfcMainDefined && hasNamedRenderExport) {
379
383
  const scope = compiled.hasScoped && compiled.scopeId ? `, __scopeId: "data-v-${compiled.scopeId}"` : "";
380
384
  emitted.edit(`${emitted.code}\nconst _sfc_main = { render${scope} };\nexport default _sfc_main;`);
@@ -1372,7 +1376,8 @@ function compileFile(filePath, cache, options, source, diagnostics) {
1372
1376
  scriptHash: result.scriptHash,
1373
1377
  macroArtifacts: result.macroArtifacts ?? [],
1374
1378
  styles: normalizeStyleBlocks(result.styles, resolved),
1375
- dependencies: [...resolved.dependencies, ...result.dependencies ?? []]
1379
+ dependencies: [...resolved.dependencies, ...result.dependencies ?? []],
1380
+ ...result.moduleShape ? { moduleShape: result.moduleShape } : {}
1376
1381
  };
1377
1382
  cache.set(filePath, compiled);
1378
1383
  return compiled;
@@ -1443,6 +1448,7 @@ function compileBatch(files, cache, options) {
1443
1448
  delete fileResult.macroArtifacts;
1444
1449
  if (fallback.macroArtifacts !== void 0) fileResult.macroArtifacts = fallback.macroArtifacts;
1445
1450
  delete fileResult.moduleShape;
1451
+ if (fallback.moduleShape !== void 0) fileResult.moduleShape = fallback.moduleShape;
1446
1452
  }
1447
1453
  for (const fileResult of result.results) {
1448
1454
  if (fileResult.errors.length > 0) continue;
@@ -1461,7 +1467,8 @@ function compileBatch(files, cache, options) {
1461
1467
  scriptHash: fileResult.scriptHash,
1462
1468
  macroArtifacts: fileResult.macroArtifacts ?? [],
1463
1469
  styles: normalizeStyleBlocks(fileResult.styles, inlinedByPath.get(fileResult.path)),
1464
- dependencies: [...inlinedByPath.get(fileResult.path)?.dependencies ?? [], ...fileResult.dependencies ?? []]
1470
+ dependencies: [...inlinedByPath.get(fileResult.path)?.dependencies ?? [], ...fileResult.dependencies ?? []],
1471
+ ...fileResult.moduleShape ? { moduleShape: fileResult.moduleShape } : {}
1465
1472
  });
1466
1473
  if (fileResult.errors.length > 0) console.error(formatCompileErrorMessage(fileResult.path, fileResult.errors));
1467
1474
  if (fileResult.warnings.length > 0) fileResult.warnings.forEach((warning) => {
@@ -1526,7 +1533,7 @@ function resolveCompilerIdentity() {
1526
1533
  */
1527
1534
  function computePrecompileCacheKey(compileOptions) {
1528
1535
  const material = stableStringify({
1529
- format: 4,
1536
+ format: 5,
1530
1537
  compiler: resolveCompilerIdentity(),
1531
1538
  options: compileOptions
1532
1539
  });
@@ -1645,7 +1652,7 @@ function encodePrecompileManifest(options) {
1645
1652
  const indexBody = compressBody(Buffer.from(JSON.stringify(index), "utf8"));
1646
1653
  const payloadBody = compressBody(Buffer.concat(records));
1647
1654
  const header = Buffer.from(JSON.stringify({
1648
- format: 4,
1655
+ format: 5,
1649
1656
  key,
1650
1657
  codec: hasZstd ? "zstd" : "gzip",
1651
1658
  index: indexBody.length,
@@ -1721,7 +1728,7 @@ function decodePrecompileManifest(bytes, options) {
1721
1728
  return reject("unparsable header");
1722
1729
  }
1723
1730
  if (typeof header !== "object" || header === null || Array.isArray(header)) return reject("unrecognized header");
1724
- if (header.format !== 4 || header.key !== key) return reject("foreign format or key");
1731
+ if (header.format !== 5 || header.key !== key) return reject("foreign format or key");
1725
1732
  if (!isByteLength(header.index) || !isByteLength(header.payload)) return reject("unrecognized body lengths");
1726
1733
  const indexStart = headerEnd + 1;
1727
1734
  const payloadStart = indexStart + header.index;
@@ -2516,10 +2523,15 @@ function registerSfcModule(state, code, filePath, isSsr) {
2516
2523
  }
2517
2524
  //#endregion
2518
2525
  //#region src/plugin/tree-shaking.ts
2519
- /** Template-only client output has no authored top-level script effects. */
2526
+ /**
2527
+ * Whether the module emits nothing but its render export: template-only client
2528
+ * output with no `<style>` block and no CSS. Style imports, injected CSS and
2529
+ * attached `styles` are side effects, so an SFC imported for its styles stays,
2530
+ * as with `@vitejs/plugin-vue` (#11544).
2531
+ */
2520
2532
  function isPureTemplateOnlyModule(compiled) {
2521
2533
  const shape = compiled?.moduleShape;
2522
- return !!(shape?.hasNamedRenderExport && !shape.hasDefaultExport && !shape.hasSfcMainDefined);
2534
+ return !!(shape?.hasNamedRenderExport && !shape.hasDefaultExport && !shape.hasSfcMainDefined && !compiled.styles?.length && !compiled.css);
2523
2535
  }
2524
2536
  function resolveTemplateOnlySfcId(state, source, isSsr, querySuffix) {
2525
2537
  const id = toPluginVisibleVirtualId(source, isSsr, querySuffix);
@@ -1138,6 +1138,7 @@ interface VizeVueFeatures {
1138
1138
  }
1139
1139
  //#endregion
1140
1140
  //#region src/utils/module-output.d.ts
1141
+ /** The native `moduleShape`: offsets are UTF-8 bytes into the module. */
1141
1142
  type ModuleOutputInfo = {
1142
1143
  hasDefaultExport: boolean;
1143
1144
  hasSfcMainDefined: boolean;
@@ -1145,11 +1146,7 @@ type ModuleOutputInfo = {
1145
1146
  hasNamedSsrRenderExport: boolean;
1146
1147
  defaultExportKeywordEnd: number | null;
1147
1148
  defaultExportStart: number | null; /** End offset of the whole `export default ...` statement, or `null`. */
1148
- defaultExportEnd: number | null;
1149
- /**
1150
- * Whether the default export's declaration is exactly the `_sfc_main`
1151
- * identifier -- the only shape {@link insertBeforeSfcMainDefaultExport} acts on.
1152
- */
1149
+ defaultExportEnd: number | null; /** Whether the default export's declaration is exactly the `_sfc_main` identifier. */
1153
1150
  defaultExportIsSfcMain: boolean;
1154
1151
  };
1155
1152
  //#endregion
@@ -1200,9 +1197,8 @@ interface CompiledModule {
1200
1197
  dependencies?: string[];
1201
1198
  /**
1202
1199
  * Module shape reported by the native compiler, so `generateOutput` need not
1203
- * re-parse the emitted module (#3425). Absent for a cache entry written before
1204
- * the field existed, and for the rspack and unplugin builders, which never set
1205
- * it — both fall back to parsing.
1200
+ * re-parse the emitted module (#3425). Every compile here carries it (#11544);
1201
+ * the rspack and unplugin builders never set it and fall back to parsing.
1206
1202
  */
1207
1203
  moduleShape?: ModuleOutputInfo;
1208
1204
  }
@@ -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-mem20MPI.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-ChOAu19s.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-DOjZaMiI.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-BzoGUulL.mjs");
403
+ const { vize } = await import("./plugin-Bmz-K8re.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.670.0",
3
+ "version": "0.672.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.670.0",
55
- "@vizejs/unplugin": "0.670.0",
54
+ "@vizejs/native": "0.672.0",
55
+ "@vizejs/unplugin": "0.672.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.670.0"
60
+ "vize": "0.672.0"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/node": "25.9.2",
@@ -1,2 +0,0 @@
1
- import { t as vize } from "./plugin-DZ3byUmi.mjs";
2
- export { vize };