@vizejs/nuxt 0.817.0 → 0.819.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 +38 -10
  2. package/package.json +7 -7
package/dist/index.mjs CHANGED
@@ -929,7 +929,7 @@ function findMatchingParen(code, openParenIndex) {
929
929
  }
930
930
  return -1;
931
931
  }
932
- const NAMED_IMPORT_RE = /^import\s*\{([\s\S]*?)\}\s*from\s*(['"])(vue|#imports|#entry)\2\s*;?/gm;
932
+ const NAMED_IMPORT_RE = /^import\s*\{([^{}]*?)\}\s*from\s*(['"])(vue(?:\/dist\/[^'"\r\n]+)?|#imports|#entry)\2\s*;?/gm;
933
933
  function parseNamedImportSpecifiers(specifierSource) {
934
934
  return specifierSource.split(",").map((specifier) => specifier.trim()).filter(Boolean).flatMap((specifier) => {
935
935
  const withoutType = specifier.replace(/^type\s+/, "").trim();
@@ -961,8 +961,11 @@ function renderNamedImport(specifiers, source, quote) {
961
961
  function preserveExplicitVueImportsFromNuxtAutoImports(originalCode, injectedCode) {
962
962
  const originalVueSpecifiers = /* @__PURE__ */ new Map();
963
963
  for (const statement of collectNamedImports(originalCode)) {
964
- if (statement.source !== "vue") continue;
965
- for (const specifier of statement.specifiers) originalVueSpecifiers.set(specifier.local, specifier);
964
+ if (statement.source !== "vue" && !statement.source.startsWith("vue/dist/")) continue;
965
+ for (const specifier of statement.specifiers) originalVueSpecifiers.set(specifier.local, {
966
+ ...specifier,
967
+ source: statement.source
968
+ });
966
969
  }
967
970
  if (originalVueSpecifiers.size === 0) return injectedCode;
968
971
  const restoredSpecifiers = /* @__PURE__ */ new Map();
@@ -990,11 +993,18 @@ function preserveExplicitVueImportsFromNuxtAutoImports(originalCode, injectedCod
990
993
  for (const replacement of replacements.reverse()) output = output.slice(0, replacement.start) + replacement.text + output.slice(replacement.end);
991
994
  const currentVueLocals = /* @__PURE__ */ new Set();
992
995
  for (const statement of collectNamedImports(output)) {
993
- if (statement.source !== "vue") continue;
996
+ if (statement.source !== "vue" && !statement.source.startsWith("vue/dist/")) continue;
994
997
  for (const specifier of statement.specifiers) currentVueLocals.add(specifier.local);
995
998
  }
996
999
  const missing = [...restoredSpecifiers.values()].filter((specifier) => !currentVueLocals.has(specifier.local));
997
- if (missing.length > 0) output = `${renderNamedImport(missing, "vue", "\"")}\n${output}`;
1000
+ const missingBySource = /* @__PURE__ */ new Map();
1001
+ for (const specifier of missing) {
1002
+ const specifiers = missingBySource.get(specifier.source) ?? [];
1003
+ specifiers.push(specifier);
1004
+ missingBySource.set(specifier.source, specifiers);
1005
+ }
1006
+ const restoredImports = [...missingBySource].map(([source, specifiers]) => renderNamedImport(specifiers, source, "\""));
1007
+ if (restoredImports.length > 0) output = `${restoredImports.join("\n")}\n${output}`;
998
1008
  return output.replace(/\n{3,}/g, "\n\n");
999
1009
  }
1000
1010
  function preserveExplicitVueImportsFromVizeModuleSource(id, code) {
@@ -1878,17 +1888,35 @@ const VUE_SSR_EXTERNAL = [
1878
1888
  "vue/server-renderer",
1879
1889
  "@vue/server-renderer"
1880
1890
  ];
1881
- const VUE_RUNTIME_DEDUPE = [
1882
- "vue",
1891
+ const VUE_RUNTIME_PACKAGES = [
1883
1892
  "@vue/reactivity",
1884
1893
  "@vue/runtime-core",
1885
1894
  "@vue/runtime-dom",
1886
1895
  "@vue/shared"
1887
1896
  ];
1888
- function dedupeVueRuntimePackages(vite) {
1897
+ function packageDirectory(from, name) {
1898
+ try {
1899
+ return dirname(realpathSync(createRequire(join(from, "package.json")).resolve(`${name}/package.json`)));
1900
+ } catch {
1901
+ return;
1902
+ }
1903
+ }
1904
+ /**
1905
+ * Dedupe makes Vite resolve a package from the project, whoever imports it. The
1906
+ * project can also hold an `@vue/*` copy that its `vue` does not use, such as
1907
+ * the one another dependency pins, and Vue would then run on that copy. So an
1908
+ * `@vue/*` package is deduped only where the project resolves Vue's own copy.
1909
+ */
1910
+ function dedupeVueRuntimePackages(vite, rootDir) {
1889
1911
  vite.resolve ||= {};
1890
1912
  const dedupe = new Set(vite.resolve.dedupe ?? []);
1891
- for (const packageName of VUE_RUNTIME_DEDUPE) dedupe.add(packageName);
1913
+ dedupe.add("vue");
1914
+ const vue = packageDirectory(rootDir, "vue");
1915
+ const runtime = vue && packageDirectory(vue, "@vue/runtime-dom");
1916
+ for (const name of VUE_RUNTIME_PACKAGES) {
1917
+ const own = vue && (packageDirectory(vue, name) ?? (runtime && packageDirectory(runtime, name)));
1918
+ if (own && own === packageDirectory(rootDir, name)) dedupe.add(name);
1919
+ }
1892
1920
  vite.resolve.dedupe = [...dedupe];
1893
1921
  }
1894
1922
  function ssrRolldownOptions(config) {
@@ -2084,7 +2112,7 @@ async function setupVizeNuxtModule(raw, nuxt) {
2084
2112
  if (nuxt.options.dev !== false) return;
2085
2113
  isNuxtBuild = true;
2086
2114
  nuxt.options.vite ||= {};
2087
- dedupeVueRuntimePackages(nuxt.options.vite);
2115
+ dedupeVueRuntimePackages(nuxt.options.vite, nuxt.options.rootDir);
2088
2116
  });
2089
2117
  nuxt.hook("vite:extendConfig", (config, context) => {
2090
2118
  if (nuxt.options.dev === false && context?.isServer) externalizeVueRuntimeForNuxtSsr(config);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/nuxt",
3
- "version": "0.817.0",
3
+ "version": "0.819.0",
4
4
  "description": "Nuxt module for Vize - compiler, musea gallery, linter, and type checker",
5
5
  "keywords": [
6
6
  "compiler",
@@ -50,16 +50,16 @@
50
50
  },
51
51
  "dependencies": {
52
52
  "@nuxt/kit": "3.21.8",
53
- "@vizejs/native": "0.817.0",
54
- "@vizejs/nuxt-lint-config": "0.817.0",
55
- "@vizejs/vite-plugin": "0.817.0",
56
- "@vizejs/vite-plugin-musea": "0.817.0",
57
- "vize": "0.817.0"
53
+ "@vizejs/native": "0.819.0",
54
+ "@vizejs/nuxt-lint-config": "0.819.0",
55
+ "@vizejs/vite-plugin": "0.819.0",
56
+ "@vizejs/vite-plugin-musea": "0.819.0",
57
+ "vize": "0.819.0"
58
58
  },
59
59
  "devDependencies": {
60
60
  "jiti-nuxt2": "npm:jiti@1.21.7",
61
61
  "oxlint": "1.78.0",
62
- "oxlint-plugin-vize": "0.817.0",
62
+ "oxlint-plugin-vize": "0.819.0",
63
63
  "typescript": "6.0.3",
64
64
  "vite": "npm:@voidzero-dev/vite-plus-core@1.5.0",
65
65
  "vite-plus": "1.5.0",