@vizejs/nuxt 0.674.0 → 0.676.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 +64 -11
  2. package/package.json +7 -7
package/dist/index.mjs CHANGED
@@ -495,6 +495,33 @@ function patchNuxtHostVuePluginForCompilerExcludes(plugin, compilerOptions) {
495
495
  plugin[VIZE_NUXT_HOST_VUE_EXCLUDE_PATCHED] = true;
496
496
  return true;
497
497
  }
498
+ function isHostVueCompiler(entry) {
499
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) return false;
500
+ const plugin = entry;
501
+ return plugin.name === "vite:vue" && hasHostVueCompilerHooks(plugin);
502
+ }
503
+ function withoutPlugin(entry, plugin) {
504
+ if (entry === plugin) return [];
505
+ if (!Array.isArray(entry)) return entry;
506
+ return entry.filter((item) => item !== plugin).map((item) => withoutPlugin(item, plugin));
507
+ }
508
+ function holdsPlugin(entry, plugin) {
509
+ return entry === plugin || Array.isArray(entry) && entry.some((item) => holdsPlugin(item, plugin));
510
+ }
511
+ /**
512
+ * Nuxt lists its host `vite:vue` before its own plugins, and Vize registers with
513
+ * the modules' plugins after them. Move Vize's compile stage to the host
514
+ * compiler's place in this config, so Nuxt's transforms keep their order around
515
+ * the compiler. The registered plugin array, shared by every config, is left as
516
+ * it is.
517
+ */
518
+ function placeVizeCompileStage(plugins, stage) {
519
+ const host = plugins.findIndex(isHostVueCompiler);
520
+ const holder = plugins.findIndex((entry) => holdsPlugin(entry, stage));
521
+ if (host === -1 || holder === -1) return;
522
+ plugins[holder] = withoutPlugin(plugins[holder], stage);
523
+ plugins.splice(host, 0, stage);
524
+ }
498
525
  function hasHostVueCompilerHooks(plugin) {
499
526
  return hasHookHandler(plugin.resolveId) || hasHookHandler(plugin.load) || hasHookHandler(plugin.transform) || hasHookHandler(plugin.handleHotUpdate);
500
527
  }
@@ -888,6 +915,13 @@ const NUXT_VUE_TYPE_GATED_TRANSFORMS = new Set([
888
915
  "nuxt:prehydrate-transform",
889
916
  "nuxt:navigate-to-early-return"
890
917
  ]);
918
+ /**
919
+ * Nuxt transforms of the SFC text, ordered before the compiler, whose gate
920
+ * admits only the whole file or a template block. `nuxt:components-loader-pre`
921
+ * and `nuxt:server-only-component-transform` gate on `isVue(id)`, which a Vize
922
+ * id passes as it is.
923
+ */
924
+ const NUXT_SFC_SOURCE_TRANSFORMS = new Set(["nuxt:server-devonly:transform"]);
891
925
  /** The id Vize gives a compiled SFC module (`Foo.vue?vue&vize`). */
892
926
  const VIZE_VUE_MODULE_ID_RE = /\.vue\?vue&vize(?:-ssr)?(?:&|$)/;
893
927
  /**
@@ -901,6 +935,12 @@ function toNuxtVueTransformId(id) {
901
935
  if (marker.test(id)) return id.replace(marker, "$1vue&type=script");
902
936
  return `${id}${id.includes("?") ? "&" : "?"}vue&type=script`;
903
937
  }
938
+ /** @vitejs/plugin-vue's id for a transform of the whole SFC text: the file itself. */
939
+ function toNuxtSfcSourceTransformId(id) {
940
+ if (!isVizeGeneratedVueModuleId(id)) return id;
941
+ const queryIndex = id.indexOf("?");
942
+ return (queryIndex === -1 ? id : id.slice(0, queryIndex)).replace(/\.vue\.tsx?$/, ".vue");
943
+ }
904
944
  function isFilterPatternList(value) {
905
945
  return typeof value === "string" || value instanceof RegExp || Array.isArray(value);
906
946
  }
@@ -936,16 +976,18 @@ function admitVizeModulesInHookFilter(filter) {
936
976
  }
937
977
  /**
938
978
  * Nuxt's core transforms classify Vue submodules by their `type=` query. Vize
939
- * owns a single generated JavaScript module for the complete SFC, so expose it
940
- * as the script submodule only for those transforms and retain its canonical
941
- * Vite identity everywhere else.
979
+ * owns a single module for the complete SFC, so expose it as the script
980
+ * submodule to the transforms after the compiler and as the file itself to
981
+ * those of the SFC text, and retain its canonical Vite identity everywhere else.
942
982
  */
943
983
  function patchNuxtVueTypeGatedTransform(plugin) {
944
- if (!plugin || plugin.__vizeNuxtVueTransformPatched || !plugin.name || !NUXT_VUE_TYPE_GATED_TRANSFORMS.has(plugin.name)) return;
984
+ if (!plugin || plugin.__vizeNuxtVueTransformPatched || !plugin.name) return;
985
+ const toHostId = NUXT_VUE_TYPE_GATED_TRANSFORMS.has(plugin.name) ? toNuxtVueTransformId : NUXT_SFC_SOURCE_TRANSFORMS.has(plugin.name) ? toNuxtSfcSourceTransformId : null;
986
+ if (!toHostId) return;
945
987
  if (typeof plugin.transform === "function") {
946
988
  const original = plugin.transform;
947
989
  plugin.transform = function(code, id, ...args) {
948
- return original.call(this, code, toNuxtVueTransformId(id), ...args);
990
+ return original.call(this, code, toHostId(id), ...args);
949
991
  };
950
992
  plugin.__vizeNuxtVueTransformPatched = true;
951
993
  return;
@@ -955,7 +997,7 @@ function patchNuxtVueTypeGatedTransform(plugin) {
955
997
  if (transform.filter !== void 0) transform.filter = admitVizeModulesInHookFilter(transform.filter);
956
998
  const original = transform.handler;
957
999
  transform.handler = function(code, id, ...args) {
958
- return original.call(this, code, toNuxtVueTransformId(id), ...args);
1000
+ return original.call(this, code, toHostId(id), ...args);
959
1001
  };
960
1002
  plugin.__vizeNuxtVueTransformPatched = true;
961
1003
  }
@@ -1193,17 +1235,28 @@ function mergePlainRecords(...values) {
1193
1235
  }
1194
1236
  //#endregion
1195
1237
  //#region src/vite-compiler.ts
1196
- /** Keep lazy plugin loading and native-only registration outside the module entry. */
1197
- async function setupNuxtViteCompiler(compilerOptions, host, compiler) {
1238
+ /**
1239
+ * Keep lazy plugin loading and native-only registration outside the module
1240
+ * entry. Vize's SFC compile stage takes the host compiler's place in each
1241
+ * config; this hook runs before the module's own, which drops that compiler.
1242
+ */
1243
+ async function setupNuxtViteCompiler(compilerOptions, nuxt, compiler) {
1198
1244
  const { default: vize } = await import("@vizejs/vite-plugin");
1245
+ const host = nuxt.options;
1199
1246
  const { options: explicit, defaults } = splitNuxtCompilerDefaults(compilerOptions, compiler, host.vue?.compilerOptions);
1200
1247
  host.vite ||= {};
1201
1248
  host.vite.plugins = host.vite.plugins || [];
1202
- host.vite.plugins.push(vize({
1249
+ const plugins = vize({
1203
1250
  ...explicit,
1204
1251
  nuxtPageMeta: true,
1205
1252
  ssrModuleIdRoot: host.srcDir
1206
- }, defaults, "nuxt"));
1253
+ }, defaults, "nuxt");
1254
+ host.vite.plugins.push(plugins);
1255
+ const stage = plugins.find((plugin) => plugin.name === "vite-plugin-vize:sfc");
1256
+ if (!stage) return;
1257
+ nuxt.hook("vite:configResolved", (config) => {
1258
+ placeVizeCompileStage(config.plugins, stage);
1259
+ });
1207
1260
  }
1208
1261
  //#endregion
1209
1262
  //#region src/libraries.ts
@@ -1483,7 +1536,7 @@ async function setupVizeNuxtModule(raw, nuxt) {
1483
1536
  }
1484
1537
  await setupLintInspector(options.lint, nuxt, compilerOptions, lintGeneration, nuxt.options.dev);
1485
1538
  const usesVizeCompiler = shouldUseVizeCompiler(compilerOptions);
1486
- if (compilerOptions !== false && compilerOptions.compatibility?.hostCompiler !== true) await setupNuxtViteCompiler(compilerOptions, nuxt.options, options.compiler);
1539
+ if (compilerOptions !== false && compilerOptions.compatibility?.hostCompiler !== true) await setupNuxtViteCompiler(compilerOptions, nuxt, options.compiler);
1487
1540
  let isNuxtBuild = false;
1488
1541
  let isViteBuild = false;
1489
1542
  if (usesVizeCompiler) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/nuxt",
3
- "version": "0.674.0",
3
+ "version": "0.676.0",
4
4
  "description": "Nuxt module for Vize - compiler, musea gallery, linter, and type checker",
5
5
  "keywords": [
6
6
  "compiler",
@@ -49,15 +49,15 @@
49
49
  },
50
50
  "dependencies": {
51
51
  "@nuxt/kit": "3.21.8",
52
- "@vizejs/native": "0.674.0",
53
- "@vizejs/nuxt-lint-config": "0.674.0",
54
- "@vizejs/vite-plugin": "0.674.0",
55
- "@vizejs/vite-plugin-musea": "0.674.0",
56
- "vize": "0.674.0"
52
+ "@vizejs/native": "0.676.0",
53
+ "@vizejs/nuxt-lint-config": "0.676.0",
54
+ "@vizejs/vite-plugin": "0.676.0",
55
+ "@vizejs/vite-plugin-musea": "0.676.0",
56
+ "vize": "0.676.0"
57
57
  },
58
58
  "devDependencies": {
59
59
  "jiti-nuxt2": "npm:jiti@1.21.7",
60
- "oxlint-plugin-vize": "0.674.0",
60
+ "oxlint-plugin-vize": "0.676.0",
61
61
  "typescript": "6.0.3",
62
62
  "vite": "npm:@voidzero-dev/vite-plus-core@1.3.0",
63
63
  "vite-plus": "1.3.0",