@vizejs/vite-plugin 0.166.0 → 0.167.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 +201 -3
  2. package/package.json +3 -3
package/dist/index.mjs CHANGED
@@ -537,6 +537,13 @@ function resolveVuePath(state, id, importer) {
537
537
  return resolveViteVuePath(state.root, id, importer);
538
538
  }
539
539
  const EMPTY_NATIVE_ALIAS_RULES = [];
540
+ const VUE_PEER_RUNTIME_PACKAGES = new Set(["vue-router"]);
541
+ const VUE_PEER_RUNTIME_ESM_ENTRIES = new Map([["vue-router", [
542
+ "dist/vue-router.mjs",
543
+ "dist/vue-router.js",
544
+ "index.mjs",
545
+ "index.js"
546
+ ]]]);
540
547
  function resolveAliasRequest(state, id) {
541
548
  return resolveViteAliasRequest(id, nativeCssAliasRules(state));
542
549
  }
@@ -573,6 +580,14 @@ function resolveBareImportWithNode(state, id, importer) {
573
580
  }
574
581
  return null;
575
582
  }
583
+ function resolveBareImportFromPnpmHoistWithNode(state, id, importer) {
584
+ const { request, querySuffix } = splitViteIdQuery(id);
585
+ for (const candidate of createViteBareImportBases(state.root, importer)) {
586
+ const hoisted = resolveBareImportFromPnpmHoist(request, candidate);
587
+ if (hoisted) return `${hoisted}${querySuffix}`;
588
+ }
589
+ return null;
590
+ }
576
591
  function resolveBareImportCandidatesWithNode(state, id, importer, resolvedId) {
577
592
  for (const candidate of createViteBareImportCandidates(id, nativeCssAliasRules(state), resolvedId)) {
578
593
  const resolved = resolveBareImportWithNode(state, candidate, importer);
@@ -612,8 +627,36 @@ function resolveVueBundlerEntryWithNode(state, id, importer) {
612
627
  }
613
628
  return null;
614
629
  }
630
+ function resolveVueBundlerEntryFromPnpmHoist(state, id, importer) {
631
+ const { request, querySuffix } = splitViteIdQuery(id);
632
+ let relativeEntries;
633
+ if (request === "vue") relativeEntries = [
634
+ "dist/vue.runtime.esm-bundler.js",
635
+ "dist/vue.esm-bundler.js",
636
+ "index.mjs"
637
+ ];
638
+ else if (request.startsWith("vue/dist/") && request.endsWith(".js")) relativeEntries = [request.slice(4)];
639
+ else return null;
640
+ const packageJson = resolveBareImportFromPnpmHoistWithNode(state, "vue/package.json", importer);
641
+ if (!packageJson) return null;
642
+ const packageRoot = path.dirname(splitViteIdQuery(packageJson).request);
643
+ for (const relativeEntry of relativeEntries) {
644
+ const entry = path.join(packageRoot, relativeEntry);
645
+ if (fs.existsSync(entry)) return `${entry}${querySuffix}`;
646
+ }
647
+ return null;
648
+ }
615
649
  function isVueRuntimeRequest(id) {
616
- return splitViteIdQuery(id).request === "vue";
650
+ const request = splitViteIdQuery(id).request;
651
+ return request === "vue" || request.startsWith("vue/dist/") && request.endsWith(".js");
652
+ }
653
+ function isVuePeerRuntimeRequest(id) {
654
+ const request = splitViteIdQuery(id).request;
655
+ const packageName = getBarePackageName(request);
656
+ return packageName ? VUE_PEER_RUNTIME_PACKAGES.has(packageName) : false;
657
+ }
658
+ function isProjectVueRuntimeRequest(id) {
659
+ return isVueRuntimeRequest(id) || isVuePeerRuntimeRequest(id);
617
660
  }
618
661
  function isVueServerRendererRequest(request) {
619
662
  return request === "@vue/server-renderer" || request === "vue/server-renderer" || request.startsWith("vue/dist/") && request.endsWith("/server-renderer");
@@ -652,6 +695,104 @@ function isVuePackageEntry(id) {
652
695
  const normalized = request.split(path.sep).join("/");
653
696
  return normalized.endsWith("/node_modules/vue/index.js") || normalized.endsWith("/node_modules/vue/dist/vue.runtime.esm-bundler.js") || normalized.endsWith("/node_modules/vue/dist/vue.esm-bundler.js") || normalized.includes("/node_modules/.pnpm/vue@") || normalized.includes("/node_modules/.pnpm/@vue+");
654
697
  }
698
+ function isInsidePath(parent, child) {
699
+ const relative = path.relative(parent, child);
700
+ return relative === "" || !!relative && !relative.startsWith("..") && !path.isAbsolute(relative);
701
+ }
702
+ function normalizeNuxtVirtualImporterPath(importer) {
703
+ const { request } = splitViteIdQuery(importer);
704
+ for (const prefix of ["/@id/virtual:nuxt:", "virtual:nuxt:"]) {
705
+ if (!request.startsWith(prefix)) continue;
706
+ const encodedPath = request.slice(prefix.length);
707
+ try {
708
+ return decodeURIComponent(encodedPath);
709
+ } catch {
710
+ return encodedPath;
711
+ }
712
+ }
713
+ return null;
714
+ }
715
+ function normalizeImporterFilePath(importer) {
716
+ const nuxtVirtualPath = normalizeNuxtVirtualImporterPath(importer);
717
+ if (nuxtVirtualPath) return nuxtVirtualPath;
718
+ const request = classifyVitePluginRequest(importer);
719
+ return request.normalizedFsId ?? request.strippedVirtualPath ?? request.vizeVirtualPath ?? request.normalizedVuePath ?? splitViteIdQuery(importer).request;
720
+ }
721
+ function isProjectLocalImporter(state, importer) {
722
+ if (!importer) return false;
723
+ const importerPath = normalizeImporterFilePath(importer);
724
+ if (!path.isAbsolute(importerPath)) return false;
725
+ if (isInsidePath(state.root, importerPath)) return true;
726
+ try {
727
+ return isInsidePath(fs.realpathSync(state.root), fs.realpathSync(importerPath));
728
+ } catch {
729
+ return false;
730
+ }
731
+ }
732
+ function resolveProjectLocalPnpmVueRuntime(state, resolvedId) {
733
+ const normalizedResolvedId = normalizeResolvedVuePath(resolvedId) ?? resolvedId;
734
+ if (!isVuePackageEntry(normalizedResolvedId)) return null;
735
+ const { request, querySuffix } = splitViteIdQuery(normalizedResolvedId);
736
+ if (!request.split(path.sep).join("/").includes("/node_modules/.pnpm/")) return null;
737
+ let realPath = request;
738
+ try {
739
+ realPath = fs.realpathSync(request);
740
+ } catch {}
741
+ return isInsidePath(state.root, realPath) ? `${realPath}${querySuffix}` : null;
742
+ }
743
+ function resolveProjectLocalResolvedPath(state, resolvedId) {
744
+ const { request, querySuffix } = splitViteIdQuery(resolvedId);
745
+ if (!path.isAbsolute(request)) return null;
746
+ let realPath = request;
747
+ try {
748
+ realPath = fs.realpathSync(request);
749
+ } catch {}
750
+ return isInsidePath(state.root, realPath) ? `${realPath}${querySuffix}` : null;
751
+ }
752
+ function resolveVuePeerRuntimeEntryWithNode(state, id, importer) {
753
+ const { request, querySuffix } = splitViteIdQuery(id);
754
+ const packageName = getBarePackageName(request);
755
+ if (!packageName || !VUE_PEER_RUNTIME_PACKAGES.has(packageName)) return null;
756
+ const packageRoot = resolvePackageRootWithNode(state, packageName, importer);
757
+ if (!packageRoot || !resolveProjectLocalResolvedPath(state, packageRoot)) return null;
758
+ if (request === packageName) for (const relativeEntry of VUE_PEER_RUNTIME_ESM_ENTRIES.get(packageName) ?? ["index.mjs"]) {
759
+ const entry = path.join(packageRoot, relativeEntry);
760
+ if (fs.existsSync(entry)) return `${entry}${querySuffix}`;
761
+ }
762
+ const nodeResolved = resolveBareImportWithNode(state, id, importer);
763
+ return nodeResolved ? resolveProjectLocalResolvedPath(state, nodeResolved) : null;
764
+ }
765
+ function resolveVuePeerRuntimeEntryFromBaseWithNode(state, id, base) {
766
+ const { request, querySuffix } = splitViteIdQuery(id);
767
+ const packageName = getBarePackageName(request);
768
+ if (!packageName || !VUE_PEER_RUNTIME_PACKAGES.has(packageName)) return null;
769
+ let packageJson;
770
+ try {
771
+ packageJson = createRequire(base).resolve(`${packageName}/package.json`);
772
+ } catch {
773
+ return null;
774
+ }
775
+ const packageRoot = path.dirname(packageJson);
776
+ if (!resolveProjectLocalResolvedPath(state, packageRoot)) return null;
777
+ if (request === packageName) for (const relativeEntry of VUE_PEER_RUNTIME_ESM_ENTRIES.get(packageName) ?? ["index.mjs"]) {
778
+ const entry = path.join(packageRoot, relativeEntry);
779
+ if (fs.existsSync(entry)) return `${entry}${querySuffix}`;
780
+ }
781
+ try {
782
+ return resolveProjectLocalResolvedPath(state, `${createRequire(base).resolve(request)}${querySuffix}`);
783
+ } catch {
784
+ return null;
785
+ }
786
+ }
787
+ function resolveProjectNuxtVuePeerRuntimeEntryWithNode(state, id) {
788
+ const { request } = splitViteIdQuery(id);
789
+ if (getBarePackageName(request) !== "vue-router") return null;
790
+ const nuxtPackageJson = resolveBareImportWithNode(state, "nuxt/package.json", path.join(state.root, "package.json"));
791
+ if (!nuxtPackageJson) return null;
792
+ const nuxtPackageRoot = path.dirname(splitViteIdQuery(nuxtPackageJson).request);
793
+ if (!resolveProjectLocalResolvedPath(state, nuxtPackageRoot)) return null;
794
+ return resolveVuePeerRuntimeEntryFromBaseWithNode(state, id, path.join(nuxtPackageRoot, "package.json"));
795
+ }
655
796
  function isOptimizedVueDependency(id) {
656
797
  const { request } = splitViteIdQuery(id);
657
798
  return request.split(path.sep).join("/").includes("/node_modules/.vite/deps/vue.");
@@ -674,11 +815,50 @@ function isVueResolvableFromRoot(root) {
674
815
  function normalizeResolvedVuePath(id) {
675
816
  return normalizeViteResolvedVuePath(id);
676
817
  }
818
+ async function resolveProjectVueRuntime(ctx, state, id, importer, isSsrRequest) {
819
+ if (isSsrRequest || !isProjectVueRuntimeRequest(id) || !isProjectLocalImporter(state, importer)) return null;
820
+ const viteImporter = normalizeViteRequireBase(importer) ?? importer;
821
+ if (isVuePeerRuntimeRequest(id)) {
822
+ const nuxtPeerEntry = resolveProjectNuxtVuePeerRuntimeEntryWithNode(state, id);
823
+ if (nuxtPeerEntry) {
824
+ state.logger.log(`resolveId: resolved Nuxt Vue peer runtime ${id} to ${nuxtPeerEntry}`);
825
+ return nuxtPeerEntry;
826
+ }
827
+ const projectLocalEntry = resolveVuePeerRuntimeEntryWithNode(state, id, viteImporter);
828
+ if (projectLocalEntry) {
829
+ state.logger.log(`resolveId: resolved project-local Vue peer runtime ${id} to ${projectLocalEntry}`);
830
+ return projectLocalEntry;
831
+ }
832
+ return null;
833
+ }
834
+ const pnpmHoistedEntry = resolveVueBundlerEntryFromPnpmHoist(state, id, viteImporter);
835
+ if (pnpmHoistedEntry) {
836
+ state.logger.log(`resolveId: resolved project pnpm-hoisted Vue runtime to ${pnpmHoistedEntry}`);
837
+ return pnpmHoistedEntry;
838
+ }
839
+ try {
840
+ const resolved = await ctx.resolve(id, viteImporter, { skipSelf: true });
841
+ if (resolved && !isOptimizedVueDependency(resolved.id)) {
842
+ const projectLocalEntry = resolveProjectLocalPnpmVueRuntime(state, resolved.id);
843
+ if (projectLocalEntry) {
844
+ state.logger.log(`resolveId: resolved project-local Vue runtime to ${projectLocalEntry}`);
845
+ return projectLocalEntry;
846
+ }
847
+ }
848
+ } catch {}
849
+ const importerLocalEntry = resolveVueBundlerEntryWithNode(state, id, viteImporter);
850
+ const projectLocalEntry = importerLocalEntry ? resolveProjectLocalPnpmVueRuntime(state, importerLocalEntry) : null;
851
+ if (projectLocalEntry) {
852
+ state.logger.log(`resolveId: resolved importer-local Vue runtime to ${projectLocalEntry}`);
853
+ return projectLocalEntry;
854
+ }
855
+ return null;
856
+ }
677
857
  function nativeCssAliasRules(state) {
678
858
  return state.cssAliasRules.length === 0 ? EMPTY_NATIVE_ALIAS_RULES : state.cssAliasRules.map(toNativeCssAliasRule);
679
859
  }
680
860
  function isPotentialVizeResolveId(id) {
681
- return id.startsWith("\0") || id.startsWith("vize:") || id.startsWith("/@fs") || id === "virtual:vize-styles" || id.endsWith(".vue") || id.includes(".vue?") || id.includes(".vue.ts?") || id.includes("?macro=true") || id.includes("?definePage");
861
+ return id.startsWith("\0") || id.startsWith("vize:") || id.startsWith("/@fs") || isProjectVueRuntimeRequest(id) || id === "virtual:vize-styles" || id.endsWith(".vue") || id.includes(".vue?") || id.includes(".vue.ts?") || id.includes("?macro=true") || id.includes("?definePage");
682
862
  }
683
863
  function isPotentialVizeImporter(importer) {
684
864
  if (importer === void 0) return false;
@@ -731,6 +911,8 @@ async function resolveIdHook(ctx, state, id, importer, options) {
731
911
  const isSsrRequest = !!options?.ssr || (importerRequest?.isVizeSsrVirtual ?? false) || (importer ? isPluginVisibleSsrVirtualId(importer) : false);
732
912
  const request = classifyVitePluginRequest(id);
733
913
  const pluginVisibleVirtualPath = fromPluginVisibleVirtualId(id);
914
+ const projectVueRuntime = await resolveProjectVueRuntime(ctx, state, id, importer, isSsrRequest);
915
+ if (projectVueRuntime) return projectVueRuntime;
734
916
  if (pluginVisibleVirtualPath) {
735
917
  if (isDependencyScan) return toVirtualId(pluginVisibleVirtualPath, isSsrRequest);
736
918
  return isSsrRequest ? toPluginVisibleVirtualId(pluginVisibleVirtualPath, true, request.querySuffix) : id;
@@ -839,6 +1021,16 @@ async function resolveIdHook(ctx, state, id, importer, options) {
839
1021
  id: normalizedFsId
840
1022
  };
841
1023
  if (isVueRuntime && state.server !== null && !isOptimizedVueDependency(resolved.id)) {
1024
+ const pnpmHoistedEntry = resolveVueBundlerEntryFromPnpmHoist(state, id, cleanImporter);
1025
+ if (pnpmHoistedEntry) {
1026
+ state.logger.log(`resolveId: resolved pnpm-hoisted Vue runtime to ${pnpmHoistedEntry}`);
1027
+ return pnpmHoistedEntry;
1028
+ }
1029
+ const projectLocalEntry = resolveProjectLocalPnpmVueRuntime(state, resolved.id);
1030
+ if (projectLocalEntry) {
1031
+ state.logger.log(`resolveId: resolved project-local Vue runtime to ${projectLocalEntry}`);
1032
+ return projectLocalEntry;
1033
+ }
842
1034
  if (isVueResolvableFromRoot(state.root)) {
843
1035
  state.logger.log(`resolveId: deferring Vue runtime ${resolved.id} to Vite optimizer`);
844
1036
  return null;
@@ -876,7 +1068,13 @@ async function resolveIdHook(ctx, state, id, importer, options) {
876
1068
  }
877
1069
  } catch {}
878
1070
  if (isVueRuntime) {
879
- const vueBundlerEntry = isBuild || !isVueResolvableFromRoot(state.root) ? resolveVueBundlerEntryWithNode(state, id, cleanImporter) : null;
1071
+ const importerLocalEntry = resolveVueBundlerEntryWithNode(state, id, cleanImporter);
1072
+ const projectLocalEntry = importerLocalEntry ? resolveProjectLocalPnpmVueRuntime(state, importerLocalEntry) : null;
1073
+ if (projectLocalEntry) {
1074
+ state.logger.log(`resolveId: resolved project-local Vue runtime to ${projectLocalEntry}`);
1075
+ return projectLocalEntry;
1076
+ }
1077
+ const vueBundlerEntry = isBuild || !isVueResolvableFromRoot(state.root) ? importerLocalEntry : null;
880
1078
  if (vueBundlerEntry) {
881
1079
  state.logger.log(`resolveId: resolved Vue runtime to ${vueBundlerEntry}`);
882
1080
  return vueBundlerEntry;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/vite-plugin",
3
- "version": "0.166.0",
3
+ "version": "0.167.0",
4
4
  "description": "High-performance native Vite plugin for Vue SFC compilation powered by Vize",
5
5
  "keywords": [
6
6
  "compiler",
@@ -39,9 +39,9 @@
39
39
  "access": "public"
40
40
  },
41
41
  "dependencies": {
42
- "@vizejs/native": "0.166.0",
42
+ "@vizejs/native": "0.167.0",
43
43
  "tinyglobby": "0.2.16",
44
- "vize": "0.166.0"
44
+ "vize": "0.167.0"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@types/node": "25.7.0",