@vizejs/nuxt 0.135.0 → 0.137.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
@@ -4,6 +4,7 @@ import { NuxtMuseaOptions, NuxtMuseaOptions as NuxtMuseaOptions$1 } from "@vizej
4
4
 
5
5
  //#region src/compiler-options.d.ts
6
6
  type VizeNuxtPattern = string | RegExp;
7
+ type VizeNuxtVueVersion = 0.11 | 1 | 2 | 3 | "legacy";
7
8
  /**
8
9
  * Nuxt-facing mirror of the public `@vizejs/vite-plugin` options.
9
10
  *
@@ -12,6 +13,14 @@ type VizeNuxtPattern = string | RegExp;
12
13
  * during monorepo lint runs.
13
14
  */
14
15
  interface VizeNuxtCompilerOptions {
16
+ /**
17
+ * Vue major version for the host project.
18
+ *
19
+ * Legacy Vue projects keep the host Vue compiler in charge. When set to
20
+ * `0.11`, `1`, `2`, or `"legacy"`, the underlying Vite plugin runs in
21
+ * compatibility mode and does not intercept `.vue` files.
22
+ */
23
+ vueVersion?: VizeNuxtVueVersion;
15
24
  /** Override the public base used for dev-time asset URLs. */
16
25
  devUrlBase?: string;
17
26
  /** Files to include in compilation. */
@@ -47,6 +56,23 @@ interface VizeNuxtCompilerOptions {
47
56
  }
48
57
  //#endregion
49
58
  //#region src/options.d.ts
59
+ type VizeNuxtMajorVersion = 2 | 3 | 4;
60
+ interface VizeNuxtCompatibilityOptions {
61
+ /**
62
+ * Override the detected Nuxt major version.
63
+ *
64
+ * This exists for projects with unusual module wrappers. Most projects should
65
+ * leave it on automatic detection.
66
+ */
67
+ nuxtVersion?: VizeNuxtMajorVersion;
68
+ /**
69
+ * Override the detected Vue major version.
70
+ *
71
+ * Nuxt 2 defaults to Vue 2 compatibility mode; Nuxt 3/4 defaults to Vue 3.
72
+ * Vue 0.11, Vue 1, and Vue 2 all use host-compiler compatibility mode.
73
+ */
74
+ vueVersion?: VizeNuxtVueVersion;
75
+ }
50
76
  interface VizeNuxtBridgeOptions {
51
77
  /**
52
78
  * Re-apply Nuxt auto-import injection to Vize virtual Vue modules.
@@ -97,6 +123,13 @@ interface VizeNuxtDevOptions {
97
123
  stylesheetLinks?: boolean;
98
124
  }
99
125
  interface VizeNuxtOptions {
126
+ /**
127
+ * Host framework compatibility overrides.
128
+ *
129
+ * These are usually inferred from Nuxt itself. Set `vueVersion: 0.11`, `1`,
130
+ * `2`, or `"legacy"` for setups that must keep the host compiler.
131
+ */
132
+ compatibility?: VizeNuxtCompatibilityOptions;
100
133
  /**
101
134
  * Enable/disable the Vize compiler (Vue SFC compilation via Vite plugin).
102
135
  * Pass an object to configure the underlying `@vizejs/vite-plugin`.
@@ -140,4 +173,4 @@ interface VizeNuxtOptions {
140
173
  //#region src/index.d.ts
141
174
  declare const _default: _$nuxt_schema0.NuxtModule<VizeNuxtOptions, VizeNuxtOptions, false>;
142
175
  //#endregion
143
- export { type MuseaOptions, type NuxtMuseaOptions, type VizeNuxtBridgeOptions, type VizeNuxtCompilerOptions, type VizeNuxtDevOptions, type VizeNuxtOptions, type VizeNuxtUnoCssOptions, _default as default };
176
+ export { type MuseaOptions, type NuxtMuseaOptions, type VizeNuxtBridgeOptions, type VizeNuxtCompatibilityOptions, type VizeNuxtCompilerOptions, type VizeNuxtDevOptions, type VizeNuxtMajorVersion, type VizeNuxtOptions, type VizeNuxtUnoCssOptions, type VizeNuxtVueVersion, _default as default };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createRequire } from "node:module";
2
- import { addServerPlugin, addVitePlugin, createResolver, defineNuxtModule } from "@nuxt/kit";
2
+ import { addServerPlugin, addVitePlugin, createResolver, defineNuxtModule, getNuxtVersion, isNuxt2 } from "@nuxt/kit";
3
3
  import vize from "@vizejs/vite-plugin";
4
4
  import { musea } from "@vizejs/vite-plugin-musea";
5
5
  import fs from "node:fs";
@@ -330,9 +330,14 @@ const DEFAULT_NUXT_BRIDGE_OPTIONS = {
330
330
  };
331
331
  const DEFAULT_NUXT_UNOCSS_OPTIONS = { originalSource: {} };
332
332
  const DEFAULT_NUXT_DEV_OPTIONS = { stylesheetLinks: true };
333
- function resolveNuxtCompilerOptions(rootDir, baseURL, buildAssetsDir, compiler) {
333
+ function resolveNuxtCompilerOptions(rootDir, baseURL, buildAssetsDir, compiler, compatibility = {}) {
334
334
  if (compiler === false) return false;
335
- return buildNuxtCompilerOptions(rootDir, baseURL, buildAssetsDir, typeof compiler === "object" && compiler != null ? compiler : {});
335
+ if (compatibility.supportsViteCompiler === false) return false;
336
+ const overrides = typeof compiler === "object" && compiler != null ? compiler : {};
337
+ return buildNuxtCompilerOptions(rootDir, baseURL, buildAssetsDir, {
338
+ vueVersion: compatibility.vueVersion,
339
+ ...overrides
340
+ });
336
341
  }
337
342
  function resolveNuxtBridgeOptions(bridge) {
338
343
  if (bridge === false) return {
@@ -402,6 +407,34 @@ function appendOriginalVueSourceForUnoCss(code, normalizedId, options = {}) {
402
407
  * - Linter: `vize lint` CLI command (via `vize` bin)
403
408
  * - Type Checker: `vize check` CLI command (via `vize` bin)
404
409
  */
410
+ function getDetectedNuxtMajor(nuxt) {
411
+ try {
412
+ const version = getNuxtVersion(nuxt);
413
+ const major = Number.parseInt(version.split(".")[0] ?? "", 10);
414
+ return major === 2 || major === 3 || major === 4 ? major : null;
415
+ } catch {
416
+ return null;
417
+ }
418
+ }
419
+ function hasNuxtViteCompilerSupport(nuxt) {
420
+ const builder = nuxt.options.builder;
421
+ if (typeof builder === "string") return builder === "vite" || builder.includes("vite-builder");
422
+ if (nuxt.options.vite) return true;
423
+ try {
424
+ return !isNuxt2(nuxt);
425
+ } catch {
426
+ return true;
427
+ }
428
+ }
429
+ function getNuxtAppBaseURL(nuxt) {
430
+ return nuxt.options.app?.baseURL ?? nuxt.options.router?.base;
431
+ }
432
+ function getNuxtBuildAssetsDir(nuxt) {
433
+ return nuxt.options.app?.buildAssetsDir ?? nuxt.options.build?.publicPath;
434
+ }
435
+ function shouldUseVizeCompiler(compilerOptions) {
436
+ return compilerOptions !== false && (compilerOptions.vueVersion ?? 3) === 3;
437
+ }
405
438
  function normalizeNuxtKeyedTransformResult(id, result) {
406
439
  if (!isVizeVirtualVueModuleId(id) || result == null) return result;
407
440
  if (typeof result === "string") return normalizeNuxtInjectedKeysForVizeVirtualModule(result, id);
@@ -438,19 +471,35 @@ var src_default = defineNuxtModule({
438
471
  },
439
472
  setup(options, nuxt) {
440
473
  const resolver = createResolver(import.meta.url);
474
+ const detectedNuxtMajor = options.compatibility?.nuxtVersion ?? getDetectedNuxtMajor(nuxt) ?? 3;
475
+ const vueVersion = options.compatibility?.vueVersion ?? (detectedNuxtMajor === 2 ? 2 : 3);
476
+ const nuxtWithBuilderOptions = nuxt;
477
+ const supportsViteCompiler = hasNuxtViteCompilerSupport(nuxtWithBuilderOptions);
478
+ const appBaseURL = getNuxtAppBaseURL(nuxtWithBuilderOptions);
479
+ const buildAssetsDir = getNuxtBuildAssetsDir(nuxtWithBuilderOptions);
441
480
  const bridgeOptions = resolveNuxtBridgeOptions(options.bridge);
442
481
  const devOptions = resolveNuxtDevOptions(options.dev);
443
482
  const museaOptions = resolveNuxtMuseaOptions(options.musea);
444
483
  const unocssOptions = resolveNuxtUnoCssOptions(options.unocss);
445
- nuxt.options.vite.plugins = nuxt.options.vite.plugins || [];
446
- const compilerOptions = resolveNuxtCompilerOptions(nuxt.options.rootDir, nuxt.options.app.baseURL, nuxt.options.app.buildAssetsDir, options.compiler);
484
+ const compilerOptions = resolveNuxtCompilerOptions(nuxt.options.rootDir, appBaseURL, buildAssetsDir, options.compiler, {
485
+ supportsViteCompiler,
486
+ vueVersion
487
+ });
447
488
  if (compilerOptions !== false) {
489
+ nuxt.options.vite ||= {};
490
+ nuxt.options.vite.plugins = nuxt.options.vite.plugins || [];
448
491
  nuxt.options.vite.plugins.push(vize(compilerOptions));
492
+ }
493
+ const usesVizeCompiler = shouldUseVizeCompiler(compilerOptions);
494
+ if (usesVizeCompiler) {
449
495
  if (nuxt.options.dev && devOptions.stylesheetLinks) {
450
- const devAssetBase = compilerOptions.devUrlBase ?? buildNuxtDevAssetBase(nuxt.options.app.baseURL, nuxt.options.app.buildAssetsDir);
496
+ const devAssetBase = compilerOptions.devUrlBase ?? buildNuxtDevAssetBase(appBaseURL, buildAssetsDir);
497
+ nuxt.options.nitro ||= {};
451
498
  nuxt.options.nitro.virtual ||= {};
452
- nuxt.options.nitro.virtual["#vizejs/nuxt/dev-stylesheet-links-config"] = `export const devAssetBase = ${JSON.stringify(devAssetBase)};`;
453
- addServerPlugin(resolver.resolve("./runtime/server/dev-stylesheet-links"));
499
+ if (nuxt.options.nitro.virtual) {
500
+ nuxt.options.nitro.virtual["#vizejs/nuxt/dev-stylesheet-links-config"] = `export const devAssetBase = ${JSON.stringify(devAssetBase)};`;
501
+ addServerPlugin(resolver.resolve("./runtime/server/dev-stylesheet-links"));
502
+ }
454
503
  }
455
504
  nuxt.hook("vite:configResolved", (config) => {
456
505
  for (let i = config.plugins.length - 1; i >= 0; i--) {
@@ -462,10 +511,10 @@ var src_default = defineNuxtModule({
462
511
  });
463
512
  }
464
513
  let unimportCtx = null;
465
- if (bridgeOptions.autoImports) nuxt.hook("imports:context", (ctx) => {
514
+ if (usesVizeCompiler && bridgeOptions.autoImports) nuxt.hook("imports:context", (ctx) => {
466
515
  unimportCtx = ctx;
467
516
  });
468
- const nuxtComponentResolver = bridgeOptions.components ? createNuxtComponentResolver({
517
+ const nuxtComponentResolver = usesVizeCompiler && bridgeOptions.components ? createNuxtComponentResolver({
469
518
  buildDir: nuxt.options.buildDir,
470
519
  moduleNames: nuxt.options.modules.filter((moduleName) => typeof moduleName === "string"),
471
520
  rootDir: nuxt.options.rootDir
@@ -473,7 +522,7 @@ var src_default = defineNuxtModule({
473
522
  if (nuxtComponentResolver) nuxt.hook("components:extend", (comps) => {
474
523
  nuxtComponentResolver.register(comps);
475
524
  });
476
- if (bridgeOptions.autoImports || bridgeOptions.components || bridgeOptions.i18n || bridgeOptions.stableInjectedKeys) addVitePlugin({
525
+ if (usesVizeCompiler && (bridgeOptions.autoImports || bridgeOptions.components || bridgeOptions.i18n || bridgeOptions.stableInjectedKeys)) addVitePlugin({
477
526
  name: "vizejs:nuxt-transform-bridge",
478
527
  enforce: "post",
479
528
  async transform(code, id) {
@@ -516,7 +565,7 @@ var src_default = defineNuxtModule({
516
565
  };
517
566
  }
518
567
  });
519
- if (unocssOptions !== false) addVitePlugin({
568
+ if (usesVizeCompiler && unocssOptions !== false) addVitePlugin({
520
569
  name: "vizejs:unocss-bridge",
521
570
  configResolved(config) {
522
571
  for (const plugin of config.plugins) if (plugin.name?.startsWith("unocss:") && typeof plugin.transform === "function") {
@@ -534,8 +583,10 @@ var src_default = defineNuxtModule({
534
583
  }
535
584
  }
536
585
  });
537
- if (museaOptions !== false) {
586
+ if (museaOptions !== false && supportsViteCompiler) {
538
587
  const museaBasePath = "basePath" in museaOptions ? museaOptions.basePath : "/__musea__";
588
+ nuxt.options.vite ||= {};
589
+ nuxt.options.vite.plugins = nuxt.options.vite.plugins || [];
539
590
  nuxt.options.vite.plugins.push(...musea(museaOptions));
540
591
  nuxt.hook("listen", (_server, listener) => {
541
592
  const url = listener.url?.replace(/\/$/, "") || "http://localhost:3000";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/nuxt",
3
- "version": "0.135.0",
3
+ "version": "0.137.0",
4
4
  "description": "Nuxt module for Vize - compiler, musea gallery, linter, and type checker",
5
5
  "keywords": [
6
6
  "compiler",
@@ -41,10 +41,10 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "@nuxt/kit": "4.4.6",
44
- "@vizejs/musea-nuxt": "0.135.0",
45
- "@vizejs/vite-plugin": "0.135.0",
46
- "@vizejs/vite-plugin-musea": "0.135.0",
47
- "vize": "0.135.0"
44
+ "@vizejs/musea-nuxt": "0.137.0",
45
+ "@vizejs/vite-plugin": "0.137.0",
46
+ "@vizejs/vite-plugin-musea": "0.137.0",
47
+ "vize": "0.137.0"
48
48
  },
49
49
  "devDependencies": {
50
50
  "typescript": "6.0.3",
@@ -54,7 +54,7 @@
54
54
  "vue-router": "4.5.1"
55
55
  },
56
56
  "peerDependencies": {
57
- "nuxt": "^3.0.0 || ^4.0.0"
57
+ "nuxt": "^2.16.0 || ^3.0.0 || ^4.0.0"
58
58
  },
59
59
  "engines": {
60
60
  "node": ">=22"