@vizejs/nuxt 0.243.0 → 0.263.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,9 +1,8 @@
1
- import { defineNuxtModule } from "@nuxt/kit";
2
1
  import { MuseaOptions, MuseaOptions as MuseaOptions$1 } from "@vizejs/vite-plugin-musea";
3
2
 
4
3
  //#region src/compiler-options.d.ts
5
4
  type VizeNuxtPattern = string | RegExp;
6
- type VizeNuxtVueVersion = 0.11 | 1 | 2 | 3 | "legacy";
5
+ type VizeNuxtVueVersion = 0.11 | 1 | 2 | "2.7" | 3 | "legacy";
7
6
  interface VizeNuxtCompilerCompatibilityOptions {
8
7
  vueVersion?: VizeNuxtVueVersion;
9
8
  hostCompiler?: boolean;
@@ -24,7 +23,7 @@ interface VizeNuxtCompilerOptions {
24
23
  * Vue major version for the host project.
25
24
  *
26
25
  * Legacy Vue projects keep the host Vue compiler in charge. When set to
27
- * `0.11`, `1`, `2`, or `"legacy"`, the underlying Vite plugin runs in
26
+ * `0.11`, `1`, `2`, `"2.7"`, or `"legacy"`, the underlying Vite plugin runs in
28
27
  * compatibility mode and does not intercept `.vue` files.
29
28
  */
30
29
  vueVersion?: VizeNuxtVueVersion;
@@ -238,7 +237,81 @@ interface VizeNuxtOptions {
238
237
  nuxtMusea?: NuxtMuseaOptions;
239
238
  }
240
239
  //#endregion
240
+ //#region src/schema.d.ts
241
+ declare module "nuxt/schema" {
242
+ interface NuxtConfig {
243
+ vize?: Partial<VizeNuxtOptions>;
244
+ }
245
+ interface NuxtOptions {
246
+ vize?: Partial<VizeNuxtOptions>;
247
+ }
248
+ }
249
+ declare module "@nuxt/schema" {
250
+ interface NuxtConfig {
251
+ vize?: Partial<VizeNuxtOptions>;
252
+ }
253
+ interface NuxtOptions {
254
+ vize?: Partial<VizeNuxtOptions>;
255
+ }
256
+ }
257
+ //#endregion
241
258
  //#region src/index.d.ts
242
- declare const _default: ReturnType<typeof defineNuxtModule<VizeNuxtOptions>>;
259
+ type NuxtWithBuilderOptions = {
260
+ _version?: string;
261
+ version?: string;
262
+ hook(name: string, callback: (...args: unknown[]) => unknown): void;
263
+ options: {
264
+ app?: {
265
+ baseURL?: string;
266
+ buildAssetsDir?: string;
267
+ };
268
+ builder?: string;
269
+ build?: {
270
+ publicPath?: string;
271
+ };
272
+ buildDir: string;
273
+ dev?: boolean;
274
+ modules: unknown[];
275
+ rootDir: string;
276
+ router?: {
277
+ base?: string;
278
+ };
279
+ vite?: {
280
+ plugins?: unknown[];
281
+ resolve?: {
282
+ dedupe?: string[];
283
+ };
284
+ };
285
+ nitro?: {
286
+ virtual?: Record<string, string>;
287
+ };
288
+ vize?: Partial<VizeNuxtOptions>;
289
+ _requiredModules?: Record<string, boolean>;
290
+ _nuxtVersion?: string;
291
+ [key: string]: unknown;
292
+ };
293
+ };
294
+ type VizeNuxtModuleContext = {
295
+ nuxt?: NuxtWithBuilderOptions;
296
+ };
297
+ declare const vizeNuxtModule: ((this: VizeNuxtModuleContext | void, inlineOptions?: Partial<VizeNuxtOptions>, nuxtArg?: NuxtWithBuilderOptions) => Promise<void>) & {
298
+ getMeta: () => {
299
+ readonly name: "@vizejs/nuxt";
300
+ readonly configKey: "vize";
301
+ };
302
+ getOptions: (inlineOptions?: Partial<VizeNuxtOptions>, nuxt?: NuxtWithBuilderOptions) => VizeNuxtOptions;
303
+ meta: {
304
+ readonly name: "@vizejs/nuxt";
305
+ readonly configKey: "vize";
306
+ };
307
+ defaults: {
308
+ musea: false;
309
+ nuxtMusea: {
310
+ route: {
311
+ path: string;
312
+ };
313
+ };
314
+ };
315
+ };
243
316
  //#endregion
244
- export { type MuseaOptions, type NuxtMuseaOptions, type VizeNuxtBridgeOptions, type VizeNuxtCompatibilityOptions, type VizeNuxtCompilerCompatibilityOptions, type VizeNuxtCompilerOptions, type VizeNuxtDevOptions, type VizeNuxtMajorVersion, type VizeNuxtOptions, type VizeNuxtUnoCssOptions, type VizeNuxtVueVersion, _default as default };
317
+ export { type MuseaOptions, type NuxtMuseaOptions, type VizeNuxtBridgeOptions, type VizeNuxtCompatibilityOptions, type VizeNuxtCompilerCompatibilityOptions, type VizeNuxtCompilerOptions, type VizeNuxtDevOptions, type VizeNuxtMajorVersion, type VizeNuxtOptions, type VizeNuxtUnoCssOptions, type VizeNuxtVueVersion, vizeNuxtModule as default };
package/dist/index.mjs CHANGED
@@ -1,7 +1,6 @@
1
1
  import { createRequire } from "node:module";
2
- import { addServerPlugin, addVitePlugin, createResolver, defineNuxtModule, getNuxtVersion, isNuxt2 } from "@nuxt/kit";
3
2
  import fs from "node:fs";
4
- import path, { dirname } from "node:path";
3
+ import path, { dirname, resolve } from "node:path";
5
4
  import { createHash } from "node:crypto";
6
5
  //#region src/components.ts
7
6
  const COMPONENT_CALL_RE = /_?resolveComponent\s*\(\s*["'`]([^"'`]+)["'`]\s*(?:,\s*[^)]+)?\)/g;
@@ -54,6 +53,16 @@ function resolveImportPath(importPath) {
54
53
  }
55
54
  return importPath;
56
55
  }
56
+ function isBarePackageSpecifier(importPath) {
57
+ if (!importPath) return false;
58
+ if (importPath.startsWith(".")) return false;
59
+ if (importPath.startsWith("/")) return false;
60
+ return !path.isAbsolute(importPath);
61
+ }
62
+ function resolveDtsImportPath(baseDir, importPath) {
63
+ if (isBarePackageSpecifier(importPath)) return importPath;
64
+ return resolveImportPath(path.resolve(baseDir, importPath));
65
+ }
57
66
  function detectComponentMode(filePath) {
58
67
  if (CLIENT_COMPONENT_RE.test(filePath)) return "client";
59
68
  if (SERVER_COMPONENT_RE.test(filePath)) return "server";
@@ -176,7 +185,7 @@ function loadDtsComponents(rootDir, buildDir) {
176
185
  const name = doubleQuotedName || singleQuotedName || bareName;
177
186
  const exportName = exportNameDot || exportNameBracket;
178
187
  if (name && exportName) {
179
- const componentImport = createComponentImport(resolveImportPath(path.resolve(path.dirname(filePath), importPath)), exportName, name.startsWith("Lazy"));
188
+ const componentImport = createComponentImport(resolveDtsImportPath(path.dirname(filePath), importPath), exportName, name.startsWith("Lazy"));
180
189
  addComponentAlias(resolved, name, componentImport);
181
190
  addLazyComponentAlias(resolved, name, componentImport);
182
191
  }
@@ -188,7 +197,7 @@ function loadDtsComponents(rootDir, buildDir) {
188
197
  const [, name, , importPath, exportNameDot, exportNameBracket] = match;
189
198
  const exportName = exportNameDot || exportNameBracket;
190
199
  if (!exportName) return;
191
- const componentImport = createComponentImport(resolveImportPath(path.resolve(path.dirname(filePath), importPath)), exportName, name.startsWith("Lazy"));
200
+ const componentImport = createComponentImport(resolveDtsImportPath(path.dirname(filePath), importPath), exportName, name.startsWith("Lazy"));
192
201
  addComponentAlias(resolved, name, componentImport);
193
202
  addLazyComponentAlias(resolved, name, componentImport);
194
203
  });
@@ -421,6 +430,7 @@ function buildNuxtDevAssetBase(baseURL = "/", buildAssetsDir = "/_nuxt/") {
421
430
  function buildNuxtCompilerOptions(rootDir, baseURL = "/", buildAssetsDir = "/_nuxt/", overrides = {}) {
422
431
  const defaults = {
423
432
  devUrlBase: buildNuxtDevAssetBase(baseURL, buildAssetsDir),
433
+ handleNodeModulesVue: false,
424
434
  root: rootDir,
425
435
  scanPatterns: []
426
436
  };
@@ -643,7 +653,7 @@ const DEFAULT_NUXT_BRIDGE_OPTIONS = {
643
653
  const DEFAULT_NUXT_UNOCSS_OPTIONS = { originalSource: {} };
644
654
  const DEFAULT_NUXT_DEV_OPTIONS = { stylesheetLinks: true };
645
655
  function isLegacyVueVersion(version) {
646
- return version === .11 || version === 1 || version === 2 || version === "legacy";
656
+ return version === .11 || version === 1 || version === 2 || version === "2.7" || version === "legacy";
647
657
  }
648
658
  function normalizeNuxtCompilerCompatibilityOptions(compatibility) {
649
659
  const normalized = {};
@@ -707,7 +717,8 @@ function resolveNuxtMuseaOptions(musea) {
707
717
  //#region src/resolver.ts
708
718
  const nodeRequire = createRequire(`${process.cwd()}/package.json`);
709
719
  function createNuxtModuleResolver() {
710
- return createResolver(dirname(nodeRequire.resolve("@vizejs/nuxt")));
720
+ const moduleDir = dirname(nodeRequire.resolve("@vizejs/nuxt"));
721
+ return { resolve: (...segments) => resolve(moduleDir, ...segments) };
711
722
  }
712
723
  function readTextFile(filePath) {
713
724
  return fs.readFileSync(filePath, "utf-8");
@@ -743,24 +754,66 @@ const VUE_RUNTIME_DEDUPE = [
743
754
  "@vue/shared"
744
755
  ];
745
756
  const VUE_CLIENT_RUNTIME_IMPORT = "vue/dist/vue.runtime.esm-bundler.js";
746
- function getDetectedNuxtMajor(nuxt) {
747
- try {
748
- const version = getNuxtVersion(nuxt);
749
- const major = Number.parseInt(version.split(".")[0] ?? "", 10);
750
- return major === 2 || major === 3 || major === 4 ? major : null;
751
- } catch {
752
- return null;
757
+ const moduleMeta = {
758
+ name: "@vizejs/nuxt",
759
+ configKey: "vize"
760
+ };
761
+ const moduleDefaults = {
762
+ musea: false,
763
+ nuxtMusea: { route: { path: "/" } }
764
+ };
765
+ let nuxtKitPromise = null;
766
+ function loadNuxtKit() {
767
+ nuxtKitPromise ||= import("@nuxt/kit");
768
+ return nuxtKitPromise;
769
+ }
770
+ async function addNuxtServerPlugin(plugin) {
771
+ const { addServerPlugin } = await loadNuxtKit();
772
+ addServerPlugin(plugin);
773
+ }
774
+ async function addNuxtVitePlugin(plugin) {
775
+ const { addVitePlugin } = await loadNuxtKit();
776
+ addVitePlugin(plugin);
777
+ }
778
+ function isPlainRecord(value) {
779
+ return value != null && typeof value === "object" && !Array.isArray(value);
780
+ }
781
+ function mergePlainRecords(...values) {
782
+ const result = {};
783
+ for (const value of values) {
784
+ if (!value) continue;
785
+ for (const [key, nextValue] of Object.entries(value)) {
786
+ const currentValue = result[key];
787
+ result[key] = isPlainRecord(currentValue) && isPlainRecord(nextValue) ? mergePlainRecords(currentValue, nextValue) : nextValue;
788
+ }
753
789
  }
790
+ return result;
791
+ }
792
+ function resolveModuleOptions(inlineOptions, nuxt) {
793
+ return mergePlainRecords(moduleDefaults, nuxt?.options.vize, inlineOptions);
794
+ }
795
+ function markNuxtRequiredModule(nuxt) {
796
+ nuxt.options._requiredModules ||= {};
797
+ nuxt.options._requiredModules[moduleMeta.name] = true;
798
+ }
799
+ function registerNuxt2CompatibilityHooks(nuxt) {
800
+ if (getDetectedNuxtMajor(nuxt) !== 2) return;
801
+ nuxt.hook("close", () => {});
802
+ nuxt.hook("builder:prepared", () => {});
803
+ nuxt.hook("build:templates", () => {});
804
+ }
805
+ function getDetectedNuxtMajor(nuxt) {
806
+ const nuxtLike = nuxt;
807
+ const version = nuxtLike?._version ?? nuxtLike?.version ?? (typeof nuxtLike?.options?._nuxtVersion === "string" ? nuxtLike.options._nuxtVersion : null);
808
+ if (!version) return null;
809
+ const major = Number.parseInt(version.split(".")[0] ?? "", 10);
810
+ return major === 2 || major === 3 || major === 4 ? major : null;
754
811
  }
755
812
  function hasNuxtViteCompilerSupport(nuxt) {
756
813
  const builder = nuxt.options.builder;
757
814
  if (typeof builder === "string") return builder === "vite" || builder.includes("vite-builder");
758
815
  if (nuxt.options.vite) return true;
759
- try {
760
- return !isNuxt2(nuxt);
761
- } catch {
762
- return true;
763
- }
816
+ return getDetectedNuxtMajor(nuxt) !== 2;
764
817
  }
765
818
  function getNuxtAppBaseURL(nuxt) {
766
819
  return nuxt.options.app?.baseURL ?? nuxt.options.router?.base;
@@ -846,168 +899,173 @@ function patchNuxtAutoImportTransformPlugin(plugin, isBuild) {
846
899
  };
847
900
  plugin[VIZE_NUXT_AUTO_IMPORT_PATCHED] = true;
848
901
  }
849
- var src_default = defineNuxtModule({
850
- meta: {
851
- name: "@vizejs/nuxt",
852
- configKey: "vize"
853
- },
854
- defaults: {
855
- musea: false,
856
- nuxtMusea: { route: { path: "/" } }
857
- },
858
- async setup(options, nuxt) {
859
- const resolver = createNuxtModuleResolver();
860
- const detectedNuxtMajor = options.compatibility?.nuxtVersion ?? getDetectedNuxtMajor(nuxt) ?? 3;
861
- const vueVersion = options.compatibility?.vueVersion ?? (detectedNuxtMajor === 2 ? 2 : 3);
862
- const nuxtWithBuilderOptions = nuxt;
863
- const supportsViteCompiler = hasNuxtViteCompilerSupport(nuxtWithBuilderOptions);
864
- const appBaseURL = getNuxtAppBaseURL(nuxtWithBuilderOptions);
865
- const buildAssetsDir = getNuxtBuildAssetsDir(nuxtWithBuilderOptions);
866
- const bridgeOptions = resolveNuxtBridgeOptions(options.bridge);
867
- const devOptions = resolveNuxtDevOptions(options.dev);
868
- const museaOptions = resolveNuxtMuseaOptions(options.musea);
869
- const unocssOptions = resolveNuxtUnoCssOptions(options.unocss);
870
- if (museaOptions !== false) nuxt.hook("components:dirs", appendMuseaArtComponentIgnore);
871
- const compilerOptions = resolveNuxtCompilerOptions(nuxt.options.rootDir, appBaseURL, buildAssetsDir, options.compiler, {
872
- supportsViteCompiler,
873
- vueVersion
874
- });
875
- const usesVizeCompiler = shouldUseVizeCompiler(compilerOptions);
876
- if (compilerOptions !== false) {
877
- const { default: vize } = await import("@vizejs/vite-plugin");
878
- nuxt.options.vite ||= {};
879
- nuxt.options.vite.plugins = nuxt.options.vite.plugins || [];
880
- nuxt.options.vite.plugins.push(vize(compilerOptions));
902
+ async function setupVizeNuxtModule(options, nuxt) {
903
+ const resolver = createNuxtModuleResolver();
904
+ const detectedNuxtMajor = options.compatibility?.nuxtVersion ?? getDetectedNuxtMajor(nuxt) ?? 3;
905
+ const vueVersion = options.compatibility?.vueVersion ?? (detectedNuxtMajor === 2 ? 2 : 3);
906
+ const nuxtWithBuilderOptions = nuxt;
907
+ const supportsViteCompiler = hasNuxtViteCompilerSupport(nuxtWithBuilderOptions);
908
+ const appBaseURL = getNuxtAppBaseURL(nuxtWithBuilderOptions);
909
+ const buildAssetsDir = getNuxtBuildAssetsDir(nuxtWithBuilderOptions);
910
+ const bridgeOptions = resolveNuxtBridgeOptions(options.bridge);
911
+ const devOptions = resolveNuxtDevOptions(options.dev);
912
+ const museaOptions = resolveNuxtMuseaOptions(options.musea);
913
+ const unocssOptions = resolveNuxtUnoCssOptions(options.unocss);
914
+ if (museaOptions !== false) nuxt.hook("components:dirs", appendMuseaArtComponentIgnore);
915
+ const compilerOptions = resolveNuxtCompilerOptions(nuxt.options.rootDir, appBaseURL, buildAssetsDir, options.compiler, {
916
+ supportsViteCompiler,
917
+ vueVersion
918
+ });
919
+ const usesVizeCompiler = shouldUseVizeCompiler(compilerOptions);
920
+ if (compilerOptions !== false && compilerOptions.compatibility?.hostCompiler !== true) {
921
+ const { default: vize } = await import("@vizejs/vite-plugin");
922
+ nuxt.options.vite ||= {};
923
+ nuxt.options.vite.plugins = nuxt.options.vite.plugins || [];
924
+ nuxt.options.vite.plugins.push(vize(compilerOptions));
925
+ }
926
+ let isNuxtBuild = false;
927
+ let isViteBuild = false;
928
+ if (usesVizeCompiler) nuxt.hook("build:before", () => {
929
+ if (nuxt.options.dev !== false) return;
930
+ isNuxtBuild = true;
931
+ nuxt.options.vite ||= {};
932
+ dedupeVueRuntimePackages(nuxt.options.vite);
933
+ });
934
+ if (usesVizeCompiler) {
935
+ if (nuxt.options.dev && devOptions.stylesheetLinks) {
936
+ const devAssetBase = compilerOptions.devUrlBase ?? buildNuxtDevAssetBase(appBaseURL, buildAssetsDir);
937
+ nuxt.options.nitro ||= {};
938
+ nuxt.options.nitro.virtual ||= {};
939
+ if (nuxt.options.nitro.virtual) {
940
+ nuxt.options.nitro.virtual["#vizejs/nuxt/dev-stylesheet-links-config"] = `export const devAssetBase = ${JSON.stringify(devAssetBase)};`;
941
+ await addNuxtServerPlugin(resolver.resolve("./runtime/server/dev-stylesheet-links"));
942
+ }
881
943
  }
882
- let isNuxtBuild = false;
883
- let isViteBuild = false;
884
- if (usesVizeCompiler) nuxt.hook("build:before", () => {
885
- if (nuxt.options.dev !== false) return;
886
- isNuxtBuild = true;
887
- nuxt.options.vite ||= {};
888
- dedupeVueRuntimePackages(nuxt.options.vite);
944
+ nuxt.hook("vite:configResolved", (config) => {
945
+ isViteBuild = config.command === "build" || isNuxtBuild || nuxt.options.dev === false;
946
+ for (let i = config.plugins.length - 1; i >= 0; i--) {
947
+ const p = config.plugins[i];
948
+ const name = p && typeof p === "object" && "name" in p ? p.name : "";
949
+ if (name === "vite:vue") config.plugins.splice(i, 1);
950
+ else if (bridgeOptions.stableInjectedKeys && name === "nuxt:compiler:keyed-functions") patchNuxtKeyedFunctionsPlugin(p);
951
+ if (bridgeOptions.autoImports) patchNuxtAutoImportTransformPlugin(p, isViteBuild);
952
+ }
889
953
  });
890
- if (usesVizeCompiler) {
891
- if (nuxt.options.dev && devOptions.stylesheetLinks) {
892
- const devAssetBase = compilerOptions.devUrlBase ?? buildNuxtDevAssetBase(appBaseURL, buildAssetsDir);
893
- nuxt.options.nitro ||= {};
894
- nuxt.options.nitro.virtual ||= {};
895
- if (nuxt.options.nitro.virtual) {
896
- nuxt.options.nitro.virtual["#vizejs/nuxt/dev-stylesheet-links-config"] = `export const devAssetBase = ${JSON.stringify(devAssetBase)};`;
897
- addServerPlugin(resolver.resolve("./runtime/server/dev-stylesheet-links"));
954
+ }
955
+ let unimportCtx = null;
956
+ if (usesVizeCompiler && bridgeOptions.autoImports) nuxt.hook("imports:context", (ctx) => {
957
+ unimportCtx = ctx;
958
+ });
959
+ const nuxtComponentResolver = usesVizeCompiler && bridgeOptions.components ? createNuxtComponentResolver({
960
+ buildDir: nuxt.options.buildDir,
961
+ moduleNames: nuxt.options.modules.filter((moduleName) => typeof moduleName === "string"),
962
+ rootDir: nuxt.options.rootDir
963
+ }) : null;
964
+ if (nuxtComponentResolver) nuxt.hook("components:extend", (comps) => {
965
+ nuxtComponentResolver.register(comps);
966
+ });
967
+ if (usesVizeCompiler && (bridgeOptions.autoImports || bridgeOptions.components || bridgeOptions.i18n || bridgeOptions.stableInjectedKeys)) await addNuxtVitePlugin({
968
+ name: "vizejs:nuxt-transform-bridge",
969
+ enforce: "post",
970
+ async transform(code, id, ...args) {
971
+ if (!isVizeGeneratedVueModuleId(id) && !isVizeJsxModuleId(id)) return;
972
+ let result = code;
973
+ let changed = false;
974
+ if (nuxtComponentResolver) {
975
+ const nextComponentResult = injectNuxtComponentImports(result, (name) => {
976
+ return nuxtComponentResolver.resolve(name);
977
+ });
978
+ if (nextComponentResult !== result) {
979
+ result = nextComponentResult;
980
+ changed = true;
898
981
  }
899
982
  }
900
- nuxt.hook("vite:configResolved", (config) => {
901
- isViteBuild = config.command === "build" || isNuxtBuild || nuxt.options.dev === false;
902
- for (let i = config.plugins.length - 1; i >= 0; i--) {
903
- const p = config.plugins[i];
904
- const name = p && typeof p === "object" && "name" in p ? p.name : "";
905
- if (name === "vite:vue") config.plugins.splice(i, 1);
906
- else if (bridgeOptions.stableInjectedKeys && name === "nuxt:compiler:keyed-functions") patchNuxtKeyedFunctionsPlugin(p);
907
- if (bridgeOptions.autoImports) patchNuxtAutoImportTransformPlugin(p, isViteBuild);
983
+ if (bridgeOptions.i18n) {
984
+ const nextResult = injectNuxtI18nHelpers(result);
985
+ if (nextResult !== result) {
986
+ result = nextResult;
987
+ changed = true;
908
988
  }
909
- });
910
- }
911
- let unimportCtx = null;
912
- if (usesVizeCompiler && bridgeOptions.autoImports) nuxt.hook("imports:context", (ctx) => {
913
- unimportCtx = ctx;
914
- });
915
- const nuxtComponentResolver = usesVizeCompiler && bridgeOptions.components ? createNuxtComponentResolver({
916
- buildDir: nuxt.options.buildDir,
917
- moduleNames: nuxt.options.modules.filter((moduleName) => typeof moduleName === "string"),
918
- rootDir: nuxt.options.rootDir
919
- }) : null;
920
- if (nuxtComponentResolver) nuxt.hook("components:extend", (comps) => {
921
- nuxtComponentResolver.register(comps);
922
- });
923
- if (usesVizeCompiler && (bridgeOptions.autoImports || bridgeOptions.components || bridgeOptions.i18n || bridgeOptions.stableInjectedKeys)) addVitePlugin({
924
- name: "vizejs:nuxt-transform-bridge",
925
- enforce: "post",
926
- async transform(code, id, ...args) {
927
- if (!isVizeGeneratedVueModuleId(id) && !isVizeJsxModuleId(id)) return;
928
- let result = code;
929
- let changed = false;
930
- if (nuxtComponentResolver) {
931
- const nextComponentResult = injectNuxtComponentImports(result, (name) => {
932
- return nuxtComponentResolver.resolve(name);
933
- });
934
- if (nextComponentResult !== result) {
935
- result = nextComponentResult;
936
- changed = true;
937
- }
989
+ }
990
+ if (unimportCtx) try {
991
+ const beforeUnimport = result;
992
+ const injected = await unimportCtx.injectImports(result, id);
993
+ if (injected.imports && injected.imports.length > 0) {
994
+ result = preserveExplicitVueImportsFromNuxtAutoImports(beforeUnimport, injected.code);
995
+ changed = true;
938
996
  }
939
- if (bridgeOptions.i18n) {
940
- const nextResult = injectNuxtI18nHelpers(result);
941
- if (nextResult !== result) {
942
- result = nextResult;
943
- changed = true;
944
- }
997
+ } catch {}
998
+ if (bridgeOptions.autoImports) {
999
+ const nextResult = preserveExplicitVueImportsFromVizeModuleSource(id, result);
1000
+ if (nextResult !== result) {
1001
+ result = nextResult;
1002
+ changed = true;
945
1003
  }
946
- if (unimportCtx) try {
947
- const beforeUnimport = result;
948
- const injected = await unimportCtx.injectImports(result, id);
949
- if (injected.imports && injected.imports.length > 0) {
950
- result = preserveExplicitVueImportsFromNuxtAutoImports(beforeUnimport, injected.code);
951
- changed = true;
952
- }
953
- } catch {}
954
- if (bridgeOptions.autoImports) {
955
- const nextResult = preserveExplicitVueImportsFromVizeModuleSource(id, result);
956
- if (nextResult !== result) {
957
- result = nextResult;
958
- changed = true;
959
- }
1004
+ }
1005
+ if (bridgeOptions.stableInjectedKeys) {
1006
+ const stableKeyResult = stabilizeNuxtInjectedKeysForVizeVirtualModule(result, id);
1007
+ if (stableKeyResult !== result) {
1008
+ result = stableKeyResult;
1009
+ changed = true;
960
1010
  }
961
- if (bridgeOptions.stableInjectedKeys) {
962
- const stableKeyResult = stabilizeNuxtInjectedKeysForVizeVirtualModule(result, id);
963
- if (stableKeyResult !== result) {
964
- result = stableKeyResult;
965
- changed = true;
966
- }
1011
+ }
1012
+ if (isViteBuild && !isViteSsrTransform(args)) {
1013
+ const clientRuntimeResult = rewriteBareVueImportsToClientRuntime(result);
1014
+ if (clientRuntimeResult !== result) {
1015
+ result = clientRuntimeResult;
1016
+ changed = true;
967
1017
  }
968
- if (isViteBuild && !isViteSsrTransform(args)) {
969
- const clientRuntimeResult = rewriteBareVueImportsToClientRuntime(result);
970
- if (clientRuntimeResult !== result) {
971
- result = clientRuntimeResult;
972
- changed = true;
1018
+ }
1019
+ if (changed) return {
1020
+ code: result,
1021
+ map: null
1022
+ };
1023
+ }
1024
+ });
1025
+ if (usesVizeCompiler && unocssOptions !== false) await addNuxtVitePlugin({
1026
+ name: "vizejs:unocss-bridge",
1027
+ configResolved(config) {
1028
+ for (const plugin of config.plugins) if (plugin.name?.startsWith("unocss:") && typeof plugin.transform === "function") {
1029
+ const origTransform = plugin.transform;
1030
+ const isExtractionOnly = plugin.name.startsWith("unocss:global");
1031
+ plugin.transform = function(code, id, ...args) {
1032
+ if (isVizeVirtualVueModuleId(id)) {
1033
+ const normalizedId = normalizeVizeVirtualVueModuleId(id);
1034
+ let effectiveCode = code;
1035
+ if (isExtractionOnly && unocssOptions.originalSource !== false) effectiveCode = appendOriginalVueSourceForUnoCss(code, normalizedId, { maxBytes: unocssOptions.originalSource.maxBytes });
1036
+ return origTransform.call(this, effectiveCode, normalizedId, ...args);
973
1037
  }
974
- }
975
- if (changed) return {
976
- code: result,
977
- map: null
1038
+ return origTransform.call(this, code, id, ...args);
978
1039
  };
979
1040
  }
980
- });
981
- if (usesVizeCompiler && unocssOptions !== false) addVitePlugin({
982
- name: "vizejs:unocss-bridge",
983
- configResolved(config) {
984
- for (const plugin of config.plugins) if (plugin.name?.startsWith("unocss:") && typeof plugin.transform === "function") {
985
- const origTransform = plugin.transform;
986
- const isExtractionOnly = plugin.name.startsWith("unocss:global");
987
- plugin.transform = function(code, id, ...args) {
988
- if (isVizeVirtualVueModuleId(id)) {
989
- const normalizedId = normalizeVizeVirtualVueModuleId(id);
990
- let effectiveCode = code;
991
- if (isExtractionOnly && unocssOptions.originalSource !== false) effectiveCode = appendOriginalVueSourceForUnoCss(code, normalizedId, { maxBytes: unocssOptions.originalSource.maxBytes });
992
- return origTransform.call(this, effectiveCode, normalizedId, ...args);
993
- }
994
- return origTransform.call(this, code, id, ...args);
995
- };
996
- }
997
- }
998
- });
999
- if (museaOptions !== false && supportsViteCompiler) {
1000
- const { musea } = await import("@vizejs/vite-plugin-musea");
1001
- const museaBasePath = "basePath" in museaOptions ? museaOptions.basePath : "/__musea__";
1002
- nuxt.options.vite ||= {};
1003
- nuxt.options.vite.plugins = nuxt.options.vite.plugins || [];
1004
- nuxt.options.vite.plugins.push(...musea(museaOptions));
1005
- nuxt.hook("listen", (_server, listener) => {
1006
- const url = listener.url?.replace(/\/$/, "") || "http://localhost:3000";
1007
- console.log(` \x1b[36m➜\x1b[0m \x1b[1mMusea Gallery:\x1b[0m \x1b[36m${url}${museaBasePath}\x1b[0m`);
1008
- });
1009
1041
  }
1042
+ });
1043
+ if (museaOptions !== false && supportsViteCompiler) {
1044
+ const { musea } = await import("@vizejs/vite-plugin-musea");
1045
+ const museaBasePath = "basePath" in museaOptions ? museaOptions.basePath : "/__musea__";
1046
+ (nuxt.options.vite ||= {}).plugins ||= [];
1047
+ const museaConfig = {
1048
+ projectRoot: nuxt.options.rootDir,
1049
+ ...museaOptions
1050
+ };
1051
+ nuxt.options.vite.plugins.push(...musea(museaConfig));
1052
+ nuxt.hook("listen", (_server, listener) => {
1053
+ const url = listener.url?.replace(/\/$/, "") || "http://localhost:3000";
1054
+ console.log(` \x1b[36m➜\x1b[0m \x1b[1mMusea Gallery:\x1b[0m \x1b[36m${url}${museaBasePath}\x1b[0m`);
1055
+ });
1010
1056
  }
1057
+ }
1058
+ const vizeNuxtModule = Object.assign(async function vizeNuxtModule(inlineOptions = {}, nuxtArg) {
1059
+ const nuxt = nuxtArg ?? this?.nuxt;
1060
+ if (!nuxt) throw new Error("@vizejs/nuxt requires a Nuxt instance");
1061
+ markNuxtRequiredModule(nuxt);
1062
+ registerNuxt2CompatibilityHooks(nuxt);
1063
+ await setupVizeNuxtModule(resolveModuleOptions(inlineOptions, nuxt), nuxt);
1064
+ }, {
1065
+ getMeta: () => moduleMeta,
1066
+ getOptions: (inlineOptions = {}, nuxt) => resolveModuleOptions(inlineOptions, nuxt),
1067
+ meta: moduleMeta,
1068
+ defaults: moduleDefaults
1011
1069
  });
1012
1070
  //#endregion
1013
- export { src_default as default };
1071
+ export { vizeNuxtModule as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/nuxt",
3
- "version": "0.243.0",
3
+ "version": "0.263.0",
4
4
  "description": "Nuxt module for Vize - compiler, musea gallery, linter, and type checker",
5
5
  "keywords": [
6
6
  "compiler",
@@ -42,9 +42,9 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "@nuxt/kit": "3.11.2",
45
- "@vizejs/vite-plugin": "0.243.0",
46
- "@vizejs/vite-plugin-musea": "0.243.0",
47
- "vize": "0.243.0"
45
+ "@vizejs/vite-plugin": "0.263.0",
46
+ "@vizejs/vite-plugin-musea": "0.263.0",
47
+ "vize": "0.263.0"
48
48
  },
49
49
  "devDependencies": {
50
50
  "typescript": "6.0.3",
@@ -55,7 +55,7 @@
55
55
  },
56
56
  "peerDependencies": {
57
57
  "nuxt": "^2.16.0 || ^3.0.0 || ^4.0.0",
58
- "vite": "^8.0.0"
58
+ "vite": "^7.3.0 || ^8.0.0"
59
59
  },
60
60
  "engines": {
61
61
  "node": ">=22"