@vizejs/nuxt 0.804.0 → 0.806.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.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { c as setupLintInspector, m as hasNuxtViteCompilerSupport, o as setupNuxtLintConfigGeneration, p as getDetectedNuxtMajor, t as setupNuxtLintChecker } from "./setup-BlCKeLRP.mjs";
1
+ import { c as setupLintInspector, m as hasNuxtViteCompilerSupport, o as setupNuxtLintConfigGeneration, p as getDetectedNuxtMajor, t as setupNuxtLintChecker } from "./setup-CewfseSX.mjs";
2
2
  import { createRequire } from "node:module";
3
3
  import fs, { readFileSync, realpathSync } from "node:fs";
4
4
  import path, { dirname, join, resolve } from "node:path";
@@ -334,8 +334,13 @@ function loadRuntimeComponents(rootDir, moduleNames) {
334
334
  }
335
335
  return resolved;
336
336
  }
337
+ function normalizedPath(filePath) {
338
+ return filePath.replace(/\\/g, "/");
339
+ }
337
340
  function createNuxtComponentResolver(options) {
338
341
  const registered = /* @__PURE__ */ new Map();
342
+ const everScannedFiles = /* @__PURE__ */ new Set();
343
+ let scannedFiles = /* @__PURE__ */ new Set();
339
344
  let dtsResolved = null;
340
345
  let runtimeResolved = null;
341
346
  function getDtsResolved() {
@@ -348,6 +353,9 @@ function createNuxtComponentResolver(options) {
348
353
  }
349
354
  return {
350
355
  register(components) {
356
+ registered.clear();
357
+ scannedFiles = new Set(components.map((component) => normalizedPath(component.filePath)));
358
+ for (const file of scannedFiles) everScannedFiles.add(file);
351
359
  for (const component of components) {
352
360
  const resolved = createComponentImport(registeredComponentPath(component, components), component.export || "default", false, component.mode);
353
361
  addRegisteredComponentAlias(registered, component.pascalName, resolved);
@@ -371,7 +379,8 @@ function createNuxtComponentResolver(options) {
371
379
  const registeredResolved = selectRegisteredComponent(registered.get(normalizedName), mode);
372
380
  if (registeredResolved) return registeredResolved;
373
381
  const dtsResolved = getDtsResolved().get(normalizedName);
374
- if (matchesBuildMode(dtsResolved, mode)) return dtsResolved;
382
+ const dtsFile = dtsResolved && normalizedPath(dtsResolved.filePath);
383
+ if (!(!!dtsFile && everScannedFiles.has(dtsFile) && !scannedFiles.has(dtsFile)) && matchesBuildMode(dtsResolved, mode)) return dtsResolved;
375
384
  if (!/[A-Z]/.test(normalizedName)) return null;
376
385
  const runtimeResolved = getRuntimeResolved().get(normalizedName);
377
386
  return matchesBuildMode(runtimeResolved, mode) ? runtimeResolved : null;
@@ -379,6 +388,74 @@ function createNuxtComponentResolver(options) {
379
388
  };
380
389
  }
381
390
  //#endregion
391
+ //#region src/component-hmr.ts
392
+ const COMPONENT_FILE_EXT_RE = /\.(?:[cm]?[jt]s|vue)$/;
393
+ function resolutionKey(resolved) {
394
+ if (!resolved) return "";
395
+ return `${resolved.filePath.replace(COMPONENT_FILE_EXT_RE, "")}#${resolved.exportName}#${resolved.lazy ? "lazy" : ""}#${resolved.mode ?? ""}`;
396
+ }
397
+ /**
398
+ * The bridge resolves Nuxt components inside Vize's compiled modules, where
399
+ * Nuxt's own loader never runs, so Nuxt cannot know which of those modules
400
+ * named a component. When a component file appears or disappears, Nuxt
401
+ * rescans its components before later hot-update hooks run; this then reloads
402
+ * every compiled module whose component names now resolve differently. A page
403
+ * saved together with a new component then imports it, and a page whose
404
+ * component was renamed or deleted loses the import and warns instead of
405
+ * failing to load, as with Nuxt's loader and @vitejs/plugin-vue.
406
+ *
407
+ * Resolutions are only recorded in dev, so builds pay nothing for this.
408
+ */
409
+ function createNuxtComponentBridge(nuxtOptions) {
410
+ const resolver = createNuxtComponentResolver({
411
+ buildDir: nuxtOptions.buildDir,
412
+ moduleNames: nuxtOptions.modules.filter((moduleName) => typeof moduleName === "string"),
413
+ rootDir: nuxtOptions.rootDir
414
+ });
415
+ const dev = nuxtOptions.dev === true;
416
+ const recorded = /* @__PURE__ */ new WeakMap();
417
+ return {
418
+ register(components) {
419
+ resolver.register(components);
420
+ },
421
+ /** The resolver for one transform of `id`, which records what it resolves in dev. */
422
+ resolverFor(environment, id, mode) {
423
+ if (!dev || !environment) return (name) => resolver.resolve(name, mode);
424
+ const modules = recorded.get(environment) ?? /* @__PURE__ */ new Map();
425
+ recorded.set(environment, modules);
426
+ modules.delete(id);
427
+ let keys;
428
+ return (name) => {
429
+ const resolved = resolver.resolve(name, mode);
430
+ if (!keys) modules.set(id, {
431
+ mode,
432
+ keys: keys = /* @__PURE__ */ new Map()
433
+ });
434
+ keys.set(name, resolutionKey(resolved));
435
+ return resolved;
436
+ };
437
+ },
438
+ hotUpdate: { handler({ type, modules }) {
439
+ if (type === "update" || !this.environment) return;
440
+ const records = recorded.get(this.environment);
441
+ if (!records) return;
442
+ const affected = new Set(modules);
443
+ for (const [id, { mode, keys }] of records) {
444
+ let changed = false;
445
+ for (const [name, key] of keys) if (resolutionKey(resolver.resolve(name, mode)) !== key) {
446
+ changed = true;
447
+ break;
448
+ }
449
+ if (!changed) continue;
450
+ records.delete(id);
451
+ const module = this.environment.moduleGraph.getModuleById(id);
452
+ if (module) affected.add(module);
453
+ }
454
+ if (affected.size !== modules.length) return [...affected];
455
+ } }
456
+ };
457
+ }
458
+ //#endregion
382
459
  //#region src/lint/module-setup.ts
383
460
  /** Whether user config asks for lint, as opposed to inheriting the module default. */
384
461
  function isLintRequested(...configured) {
@@ -435,7 +512,10 @@ const closeBundleByScope = /* @__PURE__ */ new WeakMap();
435
512
  /**
436
513
  * Nuxt's Environment API client-manifest plugin consumes and then removes the
437
514
  * Vite client manifest. Rolldown/Vite can invoke the SSR closeBundle path more
438
- * than once for a single build, so make that teardown idempotent per build.
515
+ * than once for a single build, so make that teardown idempotent per build and
516
+ * environment. The hook runs once for every environment it applies to and only
517
+ * the SSR call finalizes the manifest, so an earlier client call must not
518
+ * satisfy the SSR one.
439
519
  */
440
520
  function patchNuxtClientManifestCloseBundlePlugin(plugin, buildScope) {
441
521
  if (!plugin || plugin.name !== "nuxt:client-manifest") return;
@@ -443,7 +523,7 @@ function patchNuxtClientManifestCloseBundlePlugin(plugin, buildScope) {
443
523
  if (typeof plugin.closeBundle === "function") {
444
524
  const original = plugin.closeBundle;
445
525
  plugin.closeBundle = function(...args) {
446
- return runOnceForScope(buildScope, () => original.call(this, ...args));
526
+ return runOnceForEnvironment(buildScope, environmentName(this), () => original.call(this, ...args));
447
527
  };
448
528
  plugin[VIZE_NUXT_CLIENT_MANIFEST_PATCHED] = true;
449
529
  return;
@@ -452,12 +532,23 @@ function patchNuxtClientManifestCloseBundlePlugin(plugin, buildScope) {
452
532
  if (!closeBundle || typeof closeBundle.handler !== "function") return;
453
533
  const original = closeBundle.handler;
454
534
  closeBundle.handler = function(...args) {
455
- return runOnceForScope(buildScope, () => original.call(this, ...args));
535
+ return runOnceForEnvironment(buildScope, environmentName(this), () => original.call(this, ...args));
456
536
  };
457
537
  plugin[VIZE_NUXT_CLIENT_MANIFEST_PATCHED] = true;
458
538
  }
459
- function runOnceForScope(buildScope, run) {
460
- const pending = closeBundleByScope.get(buildScope);
539
+ function environmentName(context) {
540
+ if (!context || typeof context !== "object" || !("environment" in context)) return void 0;
541
+ const environment = context.environment;
542
+ if (!environment || typeof environment !== "object" || !("name" in environment)) return;
543
+ return typeof environment.name === "string" ? environment.name : void 0;
544
+ }
545
+ function runOnceForEnvironment(buildScope, environment, run) {
546
+ let runs = closeBundleByScope.get(buildScope);
547
+ if (!runs) {
548
+ runs = /* @__PURE__ */ new Map();
549
+ closeBundleByScope.set(buildScope, runs);
550
+ }
551
+ const pending = runs.get(environment);
461
552
  if (pending) return pending;
462
553
  let next;
463
554
  try {
@@ -466,10 +557,10 @@ function runOnceForScope(buildScope, run) {
466
557
  next = Promise.reject(error);
467
558
  }
468
559
  const tracked = next.catch((error) => {
469
- if (closeBundleByScope.get(buildScope) === tracked) closeBundleByScope.delete(buildScope);
560
+ if (runs.get(environment) === tracked) runs.delete(environment);
470
561
  throw error;
471
562
  });
472
- closeBundleByScope.set(buildScope, tracked);
563
+ runs.set(environment, tracked);
473
564
  return tracked;
474
565
  }
475
566
  //#endregion
@@ -1684,23 +1775,21 @@ async function setupVizeNuxtModule(raw, nuxt) {
1684
1775
  if (usesVizeCompiler && bridgeOptions.autoImports) nuxt.hook("imports:context", (ctx) => {
1685
1776
  unimportCtx = ctx;
1686
1777
  });
1687
- const nuxtComponentResolver = usesVizeCompiler && bridgeOptions.components ? createNuxtComponentResolver({
1688
- buildDir: nuxt.options.buildDir,
1689
- moduleNames: nuxt.options.modules.filter((moduleName) => typeof moduleName === "string"),
1690
- rootDir: nuxt.options.rootDir
1691
- }) : null;
1778
+ const nuxtComponentResolver = usesVizeCompiler && bridgeOptions.components ? createNuxtComponentBridge(nuxt.options) : null;
1692
1779
  if (nuxtComponentResolver) nuxt.hook("components:extend", (comps) => {
1693
1780
  nuxtComponentResolver.register(comps);
1694
1781
  });
1695
1782
  if (usesVizeCompiler && (bridgeOptions.autoImports || bridgeOptions.components || bridgeOptions.i18n || bridgeOptions.stableInjectedKeys)) await addNuxtVitePlugin({
1696
1783
  name: "vizejs:nuxt-transform-bridge",
1697
1784
  enforce: "post",
1785
+ hotUpdate: nuxtComponentResolver?.hotUpdate,
1698
1786
  async transform(code, id, ...args) {
1699
1787
  if (!isVizeGeneratedVueModuleId(id) && !isVizeJsxModuleId(id)) return;
1700
1788
  let result = code;
1701
1789
  let changed = false;
1702
- if (nuxtComponentResolver && hasComponentBridgeInput(result)) {
1703
- const nextComponentResult = injectNuxtComponentImports(result, (name) => nuxtComponentResolver.resolve(name, isViteSsrTransform(args) ? "server" : "client"));
1790
+ const resolveComponent = nuxtComponentResolver?.resolverFor(this.environment, id, isViteSsrTransform(args) ? "server" : "client");
1791
+ if (resolveComponent && hasComponentBridgeInput(result)) {
1792
+ const nextComponentResult = injectNuxtComponentImports(result, resolveComponent);
1704
1793
  if (nextComponentResult !== result) {
1705
1794
  result = nextComponentResult;
1706
1795
  changed = true;
@@ -1,3 +1,3 @@
1
- import { a as ROOT_OXLINT_CONFIG_NAMES, d as VIZE_NUXT_LINT_CONFIG_ADDONS_HOOK, f as setupNuxtLintConfigAddons, i as resolveNuxtLintCheckerOptions, l as toNuxtLintProjectState, n as createNuxtLintCheckerWebpackPlugin, o as setupNuxtLintConfigGeneration, r as createNuxtLintCheckerVitePlugin, s as writeFileIfChanged, t as setupNuxtLintChecker, u as renderNuxtOxlintConfig } from "../setup-BlCKeLRP.mjs";
1
+ import { a as ROOT_OXLINT_CONFIG_NAMES, d as VIZE_NUXT_LINT_CONFIG_ADDONS_HOOK, f as setupNuxtLintConfigAddons, i as resolveNuxtLintCheckerOptions, l as toNuxtLintProjectState, n as createNuxtLintCheckerWebpackPlugin, o as setupNuxtLintConfigGeneration, r as createNuxtLintCheckerVitePlugin, s as writeFileIfChanged, t as setupNuxtLintChecker, u as renderNuxtOxlintConfig } from "../setup-CewfseSX.mjs";
2
2
  export * from "@vizejs/nuxt-lint-config";
3
3
  export { ROOT_OXLINT_CONFIG_NAMES, VIZE_NUXT_LINT_CONFIG_ADDONS_HOOK, createNuxtLintCheckerVitePlugin, createNuxtLintCheckerWebpackPlugin, renderNuxtOxlintConfig, resolveNuxtLintCheckerOptions, setupNuxtLintChecker, setupNuxtLintConfigAddons, setupNuxtLintConfigGeneration, toNuxtLintProjectState, writeFileIfChanged };
@@ -554,6 +554,7 @@ async function importConfigModuleWithDependencies(configPath, registerModuleHook
554
554
  let temporary;
555
555
  try {
556
556
  temporary = await realpath(await mkdtemp(join(tmpdir(), "vize-config-module-")));
557
+ await mkdir(join(temporary, "node_modules"), { mode: 448 });
557
558
  } catch (error) {
558
559
  finishAdapter();
559
560
  throw error;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/nuxt",
3
- "version": "0.804.0",
3
+ "version": "0.806.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.804.0",
54
- "@vizejs/nuxt-lint-config": "0.804.0",
55
- "@vizejs/vite-plugin": "0.804.0",
56
- "@vizejs/vite-plugin-musea": "0.804.0",
57
- "vize": "0.804.0"
53
+ "@vizejs/native": "0.806.0",
54
+ "@vizejs/nuxt-lint-config": "0.806.0",
55
+ "@vizejs/vite-plugin": "0.806.0",
56
+ "@vizejs/vite-plugin-musea": "0.806.0",
57
+ "vize": "0.806.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.804.0",
62
+ "oxlint-plugin-vize": "0.806.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",