@vizejs/vite-plugin 0.291.0 → 0.302.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.
Files changed (2) hide show
  1. package/dist/index.mjs +34 -64
  2. package/package.json +4 -3
package/dist/index.mjs CHANGED
@@ -3,12 +3,12 @@ import { createRequire } from "node:module";
3
3
  import { 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
- import * as vite from "vite";
7
- import { parseSync } from "vite";
6
+ import { parseSync } from "oxc-parser";
8
7
  import fs from "node:fs";
9
8
  import { glob } from "tinyglobby";
10
9
  import path from "node:path";
11
10
  import { pathToFileURL } from "node:url";
11
+ import * as vite from "vite";
12
12
  //#region src/hmr.ts
13
13
  function hasHmrChanges(prev, next) {
14
14
  if (!prev) return true;
@@ -624,7 +624,23 @@ function inlineStyleSrcBlocks(source, filePath, dependencies) {
624
624
  return `<style${stripSrcAttribute(`${beforeSrc}${afterSrc}`)}>\n${imported.content}\n</style>`;
625
625
  });
626
626
  }
627
+ /**
628
+ * Cheap necessary condition for an SFC block carrying a `src` attribute.
629
+ *
630
+ * `extractSfcSrcInfo` parses a full SFC descriptor, so calling it for every file
631
+ * costs a second whole-source parse per compile on top of the one the compiler
632
+ * itself performs -- and block `src` attributes are rare (roughly 4% of files in
633
+ * a real app). Any `<script src>`/`<template src>`/`<style src>` necessarily
634
+ * contains `src` followed by `=`, so a source without this substring provably
635
+ * has nothing to inline and can skip the descriptor parse entirely. False
636
+ * positives (e.g. `<img src=...>` in a template) simply take the original path.
637
+ */
638
+ const SFC_SRC_ATTRIBUTE_HINT = /\bsrc\s*=/i;
627
639
  function resolveSfcSrcImports(filePath, source) {
640
+ if (!SFC_SRC_ATTRIBUTE_HINT.test(source)) return {
641
+ source,
642
+ dependencies: []
643
+ };
628
644
  const dependencies = [];
629
645
  const srcInfo = native.extractSfcSrcInfo(source, filePath);
630
646
  let resolvedSource = source;
@@ -1649,67 +1665,21 @@ function createVirtualTypeScriptTransformer(viteApi) {
1649
1665
  throw new Error("Installed Vite does not expose transformWithOxc or transformWithEsbuild");
1650
1666
  };
1651
1667
  }
1652
- const TYPE_DECLARATION_RE = /\b(?:interface|type|enum|namespace|declare)\s+[A-Za-z_$]/;
1653
- const TYPE_ASSERTION_RE = /\bas\s+(?:const|unknown|never|any|string|number|boolean|readonly\b|[A-Z][A-Za-z0-9_$]*(?:\s*[<[{&|),;=]|$))/;
1654
- const TYPED_BINDING_RE = /\b(?:const|let|var)\s+[A-Za-z_$][\w$]*\s*:/;
1655
- const GENERIC_FUNCTION_RE = /\bfunction\s+[A-Za-z_$][\w$]*\s*<[^>{}]*>\s*\(/;
1656
- const TYPED_PARAMETER_RE = /[(,]\s*(?:\.\.\.)?[A-Za-z_$][\w$]*\??\s*:\s*[^,)=]+/;
1657
- const RETURN_TYPE_RE = /\)\s*:\s*[^=<{;]+[{=>]/;
1658
- const ACCESS_MODIFIER_RE = /\b(?:public|private|protected|readonly|abstract|implements)\b/;
1659
- const SATISFIES_RE = /\bsatisfies\s+[A-Za-z_$]/;
1660
- function hasUnbalancedDelimiters(code) {
1661
- const stack = [];
1662
- let quote = null;
1663
- let escaped = false;
1664
- let lineComment = false;
1665
- let blockComment = false;
1666
- for (let index = 0; index < code.length; index += 1) {
1667
- const char = code[index];
1668
- const next = code[index + 1];
1669
- if (lineComment) {
1670
- if (char === "\n" || char === "\r") lineComment = false;
1671
- continue;
1672
- }
1673
- if (blockComment) {
1674
- if (char === "*" && next === "/") {
1675
- blockComment = false;
1676
- index += 1;
1677
- }
1678
- continue;
1679
- }
1680
- if (quote) {
1681
- if (escaped) escaped = false;
1682
- else if (char === "\\") escaped = true;
1683
- else if (char === quote) quote = null;
1684
- continue;
1685
- }
1686
- if (char === "/" && next === "/") {
1687
- lineComment = true;
1688
- index += 1;
1689
- continue;
1690
- }
1691
- if (char === "/" && next === "*") {
1692
- blockComment = true;
1693
- index += 1;
1694
- continue;
1695
- }
1696
- if (char === "'" || char === "\"" || char === "`") {
1697
- quote = char;
1698
- continue;
1699
- }
1700
- if (char === "{" || char === "(" || char === "[") {
1701
- stack.push(char);
1702
- continue;
1703
- }
1704
- if (char === "}" || char === ")" || char === "]") {
1705
- const open = stack.pop();
1706
- if (char === "}" && open !== "{" || char === ")" && open !== "(" || char === "]" && open !== "[") return true;
1707
- }
1708
- }
1709
- return quote !== null || blockComment || stack.length > 0;
1710
- }
1711
- function needsVirtualTypeScriptTransform(code) {
1712
- return TYPE_DECLARATION_RE.test(code) || TYPE_ASSERTION_RE.test(code) || TYPED_BINDING_RE.test(code) || GENERIC_FUNCTION_RE.test(code) || TYPED_PARAMETER_RE.test(code) || RETURN_TYPE_RE.test(code) || ACCESS_MODIFIER_RE.test(code) || SATISFIES_RE.test(code) || hasUnbalancedDelimiters(code);
1668
+ /**
1669
+ * Report whether `realPath` names a module Vize's own compiler emitted.
1670
+ *
1671
+ * Vize's Rust emitter guarantees plain JavaScript for every module it produces
1672
+ * (`ensure_javascript_output` at the napi boundary), so re-running Vite's
1673
+ * TypeScript strip over emitter output is a pure re-print. Every emitted module
1674
+ * is recorded in one of the two environment caches, so cache membership is the
1675
+ * cheap, allocation-free proof that the code came from the emitter.
1676
+ *
1677
+ * The probe fails safe: a module the caches do not know about still gets the
1678
+ * strip, which keeps hand-written and malformed virtual modules behaving
1679
+ * exactly as they did before.
1680
+ */
1681
+ function isVizeEmitterOutput(state, realPath) {
1682
+ return state.cache.has(realPath) || state.ssrCache.has(realPath);
1713
1683
  }
1714
1684
  const transformVirtualTypeScript = createVirtualTypeScriptTransformer(vite);
1715
1685
  function getOxcDumpPath(root, realPath) {
@@ -1731,7 +1701,7 @@ function formatUnknownError$1(error) {
1731
1701
  return error instanceof Error ? error.message : String(error);
1732
1702
  }
1733
1703
  async function transformVizeVirtualModule(state, code, realPath, ssr, forceTypeScriptTransform = false) {
1734
- const needsTsTransform = forceTypeScriptTransform || needsVirtualTypeScriptTransform(code);
1704
+ const needsTsTransform = forceTypeScriptTransform || !isVizeEmitterOutput(state, realPath);
1735
1705
  try {
1736
1706
  let transformed = (needsTsTransform ? await transformVirtualTypeScript(code, realPath) : { code }).code;
1737
1707
  if (transformed.includes("import.meta.")) transformed = applyDefineReplacements(transformed, getVirtualModuleDefines(state, ssr));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/vite-plugin",
3
- "version": "0.291.0",
3
+ "version": "0.302.0",
4
4
  "description": "High-performance native Vite plugin for Vue SFC compilation powered by Vize",
5
5
  "keywords": [
6
6
  "compiler",
@@ -45,9 +45,10 @@
45
45
  "access": "public"
46
46
  },
47
47
  "dependencies": {
48
- "@vizejs/native": "0.291.0",
48
+ "@vizejs/native": "0.302.0",
49
+ "oxc-parser": "0.133.0",
49
50
  "tinyglobby": "0.2.16",
50
- "vize": "0.291.0"
51
+ "vize": "0.302.0"
51
52
  },
52
53
  "devDependencies": {
53
54
  "@types/node": "25.9.2",