@vizejs/vite-plugin 0.665.0 → 0.667.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-CP73ozVq.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-mem20MPI.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-CAu9ew7B.mjs";
1
+ import { t as vize } from "./plugin-BAahoMod.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-CP73ozVq.mjs";
1
+ import { f as ResolvedVizeConfig } from "../types-mem20MPI.mjs";
2
2
  import { ResolvedConfig } from "vite";
3
3
 
4
4
  //#region src/internal/config-bridge.d.ts
@@ -212,32 +212,13 @@ function rewriteDefaultExportToSfcMain(code, moduleInfo = {
212
212
  return `${code.slice(0, exportStart)}const ${SFC_MAIN_NAME} =${code.slice(keywordEnd)}`;
213
213
  }
214
214
  /**
215
- * Locate `export default _sfc_main` when the caller has no analysis to hand.
216
- *
217
- * The string test is a sound pre-filter: the AST check below only succeeds when
218
- * the default export's declaration *is* the `_sfc_main` identifier, which cannot
219
- * happen unless that name occurs in the module.
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).
220
218
  */
221
- function findSfcMainDefaultExport(code) {
222
- if (!code.includes(SFC_MAIN_NAME)) return {
223
- defaultExportStart: null,
224
- defaultExportEnd: null,
225
- defaultExportIsSfcMain: false
226
- };
227
- const defaultExport = findDefaultExport(parseProgram(code));
228
- return {
229
- defaultExportStart: getNodeStart(defaultExport),
230
- defaultExportEnd: getNodeEnd(defaultExport),
231
- defaultExportIsSfcMain: isSfcMainDefaultExport(defaultExport)
232
- };
233
- }
234
- function insertBeforeSfcMainDefaultExport(code, insertion, options = {}) {
235
- const { defaultExportStart: exportStart, defaultExportEnd: exportEnd, defaultExportIsSfcMain } = options.moduleInfo ?? findSfcMainDefaultExport(code);
236
- if (!defaultExportIsSfcMain || exportStart == null) return code;
237
- if (options.normalizeSemicolon && exportEnd != null) {
238
- const suffixStart = code[exportEnd] === ";" ? exportEnd + 1 : exportEnd;
239
- return `${code.slice(0, exportStart)}${insertion}\nexport default ${SFC_MAIN_NAME};${code.slice(suffixStart)}`;
240
- }
219
+ function insertBeforeSfcMainDefaultExport(code, insertion, moduleInfo) {
220
+ const exportStart = moduleInfo.defaultExportStart;
221
+ if (!moduleInfo.defaultExportIsSfcMain || exportStart == null) return code;
241
222
  return `${code.slice(0, exportStart)}${insertion}\n${code.slice(exportStart)}`;
242
223
  }
243
224
  //#endregion
@@ -386,22 +367,25 @@ function assembleComponentOutput(compiled) {
386
367
  const hasNamedRenderExport = moduleInfo.hasNamedRenderExport;
387
368
  const hasNamedSsrRenderExport = moduleInfo.hasNamedSsrRenderExport;
388
369
  const hasSfcMainDefined = moduleInfo.hasSfcMainDefined;
370
+ let exportsSfcMain = true;
389
371
  if (hasExportDefault && !hasSfcMainDefined) {
390
372
  emitted.edit(rewriteDefaultExportToSfcMain(emitted.code, moduleInfo));
391
373
  if (compiled.hasScoped && compiled.scopeId) emitted.edit(`${emitted.code}\n_sfc_main.__scopeId = "data-v-${compiled.scopeId}";`);
392
374
  emitted.edit(`${emitted.code}\nexport default _sfc_main;`);
393
375
  } else if (hasExportDefault && hasSfcMainDefined) {
394
- if (compiled.hasScoped && compiled.scopeId) emitted.edit(insertBeforeSfcMainDefaultExport(emitted.code, `_sfc_main.__scopeId = "data-v-${compiled.scopeId}";`, { moduleInfo }));
376
+ exportsSfcMain = moduleInfo.defaultExportIsSfcMain;
377
+ if (compiled.hasScoped && compiled.scopeId) emitted.edit(insertBeforeSfcMainDefaultExport(emitted.code, `_sfc_main.__scopeId = "data-v-${compiled.scopeId}";`, moduleInfo));
395
378
  } else if (!hasExportDefault && !hasSfcMainDefined && hasNamedRenderExport) {
396
379
  const scope = compiled.hasScoped && compiled.scopeId ? `, __scopeId: "data-v-${compiled.scopeId}"` : "";
397
380
  emitted.edit(`${emitted.code}\nconst _sfc_main = { render${scope} };\nexport default _sfc_main;`);
398
381
  } else if (!hasExportDefault && !hasSfcMainDefined && hasNamedSsrRenderExport) {
399
382
  const scope = compiled.hasScoped && compiled.scopeId ? `, __scopeId: "data-v-${compiled.scopeId}"` : "";
400
383
  emitted.edit(`${emitted.code}\nconst _sfc_main = { ssrRender${scope} };\nexport default _sfc_main;`);
401
- }
384
+ } else exportsSfcMain = false;
402
385
  return {
403
386
  emitted,
404
- hasExportDefault
387
+ hasExportDefault,
388
+ exportsSfcMain
405
389
  };
406
390
  }
407
391
  //#endregion
@@ -699,7 +683,7 @@ function generateOutput(compiled, options) {
699
683
  */
700
684
  function generateOutputWithMap(compiled, options) {
701
685
  const { customElement, isProduction, isDev, ssr, hmrUpdateType, extractCss, filePath, root } = options;
702
- const { emitted, hasExportDefault } = assembleComponentOutput(compiled);
686
+ const { emitted, hasExportDefault, exportsSfcMain } = assembleComponentOutput(compiled);
703
687
  if (usesStyleImports(compiled, options)) {
704
688
  const styleImports = [];
705
689
  const cssModuleImports = [];
@@ -731,8 +715,8 @@ function generateOutputWithMap(compiled, options) {
731
715
  }
732
716
  const allImports = [...styleImports, ...cssModuleImports].join("\n");
733
717
  if (allImports) emitted.edit(insertAfterStaticImports(emitted.code, allImports));
734
- if (customElementStyleBindings.length > 0) emitted.edit(insertBeforeSfcMainDefaultExport(emitted.code, `_sfc_main.styles = [${customElementStyleBindings.join(", ")}];`, { normalizeSemicolon: true }));
735
- else if (cssModuleImports.length > 0) {
718
+ if (exportsSfcMain && customElementStyleBindings.length > 0) emitted.edit(`${emitted.code}\n_sfc_main.styles = [${customElementStyleBindings.join(", ")}];`);
719
+ else if (exportsSfcMain && cssModuleImports.length > 0) {
736
720
  const moduleBindings = [];
737
721
  for (const block of compiled.styles) if (isCssModule(block)) {
738
722
  const bindingName = typeof block.module === "string" ? block.module : "$style";
@@ -742,7 +726,7 @@ function generateOutputWithMap(compiled, options) {
742
726
  });
743
727
  }
744
728
  const cssModuleSetup = moduleBindings.map((m) => `_sfc_main.__cssModules = _sfc_main.__cssModules || {};\n_sfc_main.__cssModules[${JSON.stringify(m.name)}] = ${m.bindingName};`).join("\n");
745
- emitted.edit(insertBeforeSfcMainDefaultExport(emitted.code, cssModuleSetup, { normalizeSemicolon: true }));
729
+ emitted.edit(`${emitted.code}\n${cssModuleSetup}`);
746
730
  }
747
731
  } else if (!ssr && compiled.css && !(isProduction && extractCss)) emitted.edit(prependInlineStyleInjection(emitted.code, compiled.css, compiled.scopeId));
748
732
  if (!isProduction && isDev && hasExportDefault) {
@@ -1907,13 +1891,21 @@ async function prepareSfcSrcRequests(state, resolve, file, source) {
1907
1891
  }
1908
1892
  (state.srcResolutions ??= /* @__PURE__ */ new Map()).set(file, await resolveSfcSrcRequests(file, requests, resolve));
1909
1893
  }
1910
- /** A `load` that compiles its SFC on demand resolves the SFC's requests first. */
1894
+ /**
1895
+ * A `load` that compiles its SFC on demand resolves the SFC's requests first.
1896
+ * It returns the source it read, so that compile does not read the file again.
1897
+ */
1911
1898
  async function prepareLoadSrcRequests(state, resolve, id) {
1912
- if (!id.includes(".vue")) return;
1899
+ if (!id.includes(".vue")) return void 0;
1913
1900
  const request = classifyVitePluginRequest(id);
1914
1901
  const file = request.vizeVirtualPath ?? fromPluginVisibleVirtualId(id) ?? getLoadableVueSfcPath(request);
1915
1902
  if (!file?.endsWith(".vue") || state.cache.has(file) || state.ssrCache.has(file) || state.srcResolutions?.has(file) || !fs.existsSync(file)) return;
1916
- await prepareSfcSrcRequests(state, resolve, file, fs.readFileSync(file, "utf-8"));
1903
+ const source = fs.readFileSync(file, "utf-8");
1904
+ await prepareSfcSrcRequests(state, resolve, file, source);
1905
+ return {
1906
+ file,
1907
+ source
1908
+ };
1917
1909
  }
1918
1910
  //#endregion
1919
1911
  //#region src/plugin/precompile-run.ts
@@ -2463,30 +2455,28 @@ const VUE_PEER_RUNTIME_ESM_ENTRIES = new Map([["vue-router", [
2463
2455
  "index.mjs",
2464
2456
  "index.js"
2465
2457
  ]]]);
2466
- function getViteResolveCache(state) {
2467
- return state.viteResolveCache ??= /* @__PURE__ */ new Map();
2468
- }
2469
- function createViteResolveCacheKey(id, importer, options, environmentName) {
2470
- return JSON.stringify([
2471
- environmentName ?? null,
2472
- id,
2473
- importer ?? null,
2474
- options?.skipSelf ?? false
2475
- ]);
2476
- }
2477
- function resolveWithVite(ctx, state, id, importer, options) {
2478
- if (state.server !== null) return ctx.resolve(id, importer, options);
2479
- const cache = getViteResolveCache(state);
2480
- const key = createViteResolveCacheKey(id, importer, options, ctx.environment?.name);
2481
- const cached = cache.get(key);
2458
+ /** One answer per build and environment for `key`; the dev server can change it. */
2459
+ function oncePerBuild(ctx, state, key, resolve) {
2460
+ if (state.server !== null) return resolve();
2461
+ const cache = state.viteResolveCache ??= /* @__PURE__ */ new Map();
2462
+ const cacheKey = JSON.stringify([ctx.environment?.name ?? null, ...key]);
2463
+ const cached = cache.get(cacheKey);
2482
2464
  if (cached) return cached;
2483
- const pending = ctx.resolve(id, importer, options).catch((error) => {
2484
- cache.delete(key);
2465
+ const pending = resolve().catch((error) => {
2466
+ cache.delete(cacheKey);
2485
2467
  throw error;
2486
2468
  });
2487
- cache.set(key, pending);
2469
+ cache.set(cacheKey, pending);
2488
2470
  return pending;
2489
2471
  }
2472
+ function resolveWithVite(ctx, state, id, importer, options) {
2473
+ return oncePerBuild(ctx, state, [
2474
+ "resolve",
2475
+ id,
2476
+ importer ?? null,
2477
+ options?.skipSelf ?? false
2478
+ ], () => ctx.resolve(id, importer, options));
2479
+ }
2490
2480
  function resolveAliasRequest(state, id) {
2491
2481
  return resolveViteAliasRequest(id, nativeCssAliasRules(state));
2492
2482
  }
@@ -2731,6 +2721,17 @@ function normalizeResolvedVuePath(id) {
2731
2721
  }
2732
2722
  async function resolveProjectVueRuntime(ctx, state, id, importer, isSsrRequest) {
2733
2723
  if (isSsrRequest || !isProjectVueRuntimeRequest(id)) return null;
2724
+ const base = normalizeViteRequireBase(importer) ?? importer;
2725
+ return (await oncePerBuild(ctx, state, [
2726
+ "project-vue-runtime",
2727
+ id,
2728
+ base ? path.dirname(base) : null
2729
+ ], async () => {
2730
+ const entry = await resolveProjectVueRuntimeFrom(ctx, state, id, importer);
2731
+ return entry ? { id: entry } : null;
2732
+ }))?.id ?? null;
2733
+ }
2734
+ async function resolveProjectVueRuntimeFrom(ctx, state, id, importer) {
2734
2735
  if (isVuePeerRuntimeRequest(id)) {
2735
2736
  const nuxtPeerEntry = resolveProjectNuxtVuePeerRuntimeEntryWithNode(state, id);
2736
2737
  if (nuxtPeerEntry) {
@@ -2739,10 +2740,9 @@ async function resolveProjectVueRuntime(ctx, state, id, importer, isSsrRequest)
2739
2740
  }
2740
2741
  }
2741
2742
  if (!isProjectLocalImporter(state, importer)) return null;
2742
- const isBuild = state.server === null;
2743
2743
  const viteImporter = normalizeViteRequireBase(importer) ?? importer;
2744
2744
  if (isVuePeerRuntimeRequest(id)) {
2745
- if (!isBuild && isProjectSourceImporter(state.root, importer)) {
2745
+ if (state.server !== null && isProjectSourceImporter(state.root, importer)) {
2746
2746
  state.logger.log(`resolveId: deferring source Vue peer runtime ${id} to Vite optimizer`);
2747
2747
  return null;
2748
2748
  }
@@ -3221,9 +3221,10 @@ function loadCompiledSfcModule(state, realPath, isSsr, currentBase, needsGlobBas
3221
3221
  const customElement = isPluginVueCustomElement(state.mergedOptions, realPath);
3222
3222
  const extractCss = shouldExtractCssForRequest(state, isSsr) && !customElement;
3223
3223
  let compiled = cache.get(realPath);
3224
- if (!compiled && fs.existsSync(realPath)) {
3224
+ const source = loadOptions?.sfcSource?.file === realPath ? loadOptions.sfcSource.source : void 0;
3225
+ if (!compiled && (source !== void 0 || fs.existsSync(realPath))) {
3225
3226
  state.logger.log(`load: on-demand compiling ${realPath}`);
3226
- compiled = compileFile(realPath, cache, getCompileOptionsForRequest(state, isSsr, realPath), void 0, { logWarnings: shouldLogSfcWarnings(state, realPath) });
3227
+ compiled = compileFile(realPath, cache, getCompileOptionsForRequest(state, isSsr, realPath), source, { logWarnings: shouldLogSfcWarnings(state, realPath) });
3227
3228
  }
3228
3229
  syncCollectedCssForFile({
3229
3230
  ...state,
@@ -4744,11 +4745,12 @@ function vize(options = {}, compilerDefaults = {}, hostContext) {
4744
4745
  });
4745
4746
  },
4746
4747
  async load(id, loadOptions) {
4747
- await prepareLoadSrcRequests(state, viteHostResolve((request, importer) => this.resolve(request, importer, { skipSelf: true })), id);
4748
+ const sfcSource = await prepareLoadSrcRequests(state, viteHostResolve((request, importer) => this.resolve(request, importer, { skipSelf: true })), id);
4748
4749
  return loadHook(state, id, {
4749
4750
  ...loadOptions,
4750
4751
  ssr: resolveHookSsr(this, loadOptions),
4751
- addWatchFile: this.addWatchFile.bind(this)
4752
+ addWatchFile: this.addWatchFile.bind(this),
4753
+ sfcSource
4752
4754
  });
4753
4755
  },
4754
4756
  async transform(code, id, transformOptions) {
@@ -0,0 +1,2 @@
1
+ import { t as vize } from "./plugin-BAahoMod.mjs";
2
+ export { vize };
@@ -1144,13 +1144,7 @@ type ModuleOutputInfo = {
1144
1144
  hasNamedRenderExport: boolean;
1145
1145
  hasNamedSsrRenderExport: boolean;
1146
1146
  defaultExportKeywordEnd: number | null;
1147
- defaultExportStart: number | null;
1148
- /**
1149
- * End offset of the whole `export default ...` statement, or `null`.
1150
- *
1151
- * Recorded so {@link insertBeforeSfcMainDefaultExport} can reuse the caller's
1152
- * analysis instead of parsing the module a second time (#3425).
1153
- */
1147
+ defaultExportStart: number | null; /** End offset of the whole `export default ...` statement, or `null`. */
1154
1148
  defaultExportEnd: number | null;
1155
1149
  /**
1156
1150
  * Whether the default export's declaration is exactly the `_sfc_main`
@@ -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-CP73ozVq.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-mem20MPI.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-hkzt_w0x.mjs");
403
+ const { vize } = await import("./plugin-CcTdAxZL.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.665.0",
3
+ "version": "0.667.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.665.0",
55
- "@vizejs/unplugin": "0.665.0",
54
+ "@vizejs/native": "0.667.0",
55
+ "@vizejs/unplugin": "0.667.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.665.0"
60
+ "vize": "0.667.0"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/node": "25.9.2",
@@ -1,2 +0,0 @@
1
- import { t as vize } from "./plugin-CAu9ew7B.mjs";
2
- export { vize };