@vizejs/nuxt 0.812.0 → 0.814.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 +220 -0
  2. package/package.json +9 -8
package/dist/index.mjs CHANGED
@@ -1436,6 +1436,225 @@ function mergePlainRecords(...values) {
1436
1436
  return result;
1437
1437
  }
1438
1438
  //#endregion
1439
+ //#region src/template-diagnostics.ts
1440
+ const ALWAYS_CHECKED_TAGS = [
1441
+ "NuxtLink",
1442
+ "nuxt-link",
1443
+ "NuxtIsland",
1444
+ "nuxt-island"
1445
+ ];
1446
+ const SFC_MODULE_ID = /\.vue(?:\.tsx?)?(?:\?|$)/;
1447
+ const DESCRIBED_NODE = {
1448
+ "a function": "ArrowFunctionExpression",
1449
+ "a class": "ClassExpression",
1450
+ "a class instance": "NewExpression"
1451
+ };
1452
+ /**
1453
+ * Nuxt registers its template diagnostics transform in a `build:before` hook
1454
+ * added after every module's setup. A hook added in `modules:done` runs right
1455
+ * after it and finds it last among Nuxt's own `nodeTransform`s.
1456
+ */
1457
+ function captureNuxtTemplateDiagnostics(options) {
1458
+ if (!options.experimental?.templateDiagnostics) return void 0;
1459
+ const transforms = options.vite?.vue?.template?.compilerOptions?.nodeTransforms ?? [];
1460
+ for (let index = transforms.length - 1; index >= 0; index--) {
1461
+ const transform = transforms[index];
1462
+ if (typeof transform === "function" && transform.name === "nodeTransform") return transform;
1463
+ }
1464
+ }
1465
+ /** Nuxt's `resolveServerComponentTags`: server-only components, every way a template names them. */
1466
+ function resolveServerComponentTags(components) {
1467
+ const tags = /* @__PURE__ */ new Set();
1468
+ for (const component of components) {
1469
+ if (component.mode !== "server" || components.some((other) => other.mode !== "server" && other.pascalName === component.pascalName)) continue;
1470
+ tags.add(`${component.pascalName}`);
1471
+ tags.add(`${component.kebabName}`);
1472
+ tags.add(`Lazy${component.pascalName}`);
1473
+ tags.add(`lazy-${component.kebabName}`);
1474
+ }
1475
+ return [...tags];
1476
+ }
1477
+ function location(finding) {
1478
+ const start = {
1479
+ line: finding.line,
1480
+ column: finding.column,
1481
+ offset: finding.offset
1482
+ };
1483
+ return {
1484
+ start,
1485
+ end: start,
1486
+ source: ""
1487
+ };
1488
+ }
1489
+ function staticArg(content) {
1490
+ return {
1491
+ type: 4,
1492
+ content,
1493
+ isStatic: true
1494
+ };
1495
+ }
1496
+ function describedValue(value) {
1497
+ return { type: DESCRIBED_NODE[value ?? ""] ?? "Unknown" };
1498
+ }
1499
+ /** The props of an element for which Nuxt's transform raises exactly `finding`. */
1500
+ function findingProps(finding) {
1501
+ const loc = location(finding);
1502
+ switch (finding.kind) {
1503
+ case "link": return [{
1504
+ type: 6,
1505
+ name: finding.attribute,
1506
+ value: {
1507
+ type: 2,
1508
+ content: finding.to,
1509
+ loc
1510
+ },
1511
+ loc
1512
+ }];
1513
+ case "event": return [{
1514
+ type: 7,
1515
+ name: "model",
1516
+ rawName: finding.directive,
1517
+ modifiers: [],
1518
+ loc
1519
+ }];
1520
+ case "prop": return [{
1521
+ type: 7,
1522
+ name: "bind",
1523
+ rawName: `:${finding.prop}`,
1524
+ arg: staticArg(finding.prop ?? ""),
1525
+ exp: {
1526
+ type: 4,
1527
+ content: "",
1528
+ ast: describedValue(finding.value),
1529
+ loc
1530
+ },
1531
+ modifiers: [],
1532
+ loc
1533
+ }];
1534
+ case "island": {
1535
+ const property = {
1536
+ type: "ObjectProperty",
1537
+ computed: false,
1538
+ key: {
1539
+ type: "Identifier",
1540
+ name: finding.prop
1541
+ },
1542
+ value: describedValue(finding.value)
1543
+ };
1544
+ return [...finding.islandName == null ? [] : [{
1545
+ type: 6,
1546
+ name: "name",
1547
+ value: {
1548
+ type: 2,
1549
+ content: finding.islandName,
1550
+ loc
1551
+ },
1552
+ loc
1553
+ }], {
1554
+ type: 7,
1555
+ name: "bind",
1556
+ rawName: `:${finding.islandProp}`,
1557
+ arg: staticArg(finding.islandProp ?? ""),
1558
+ exp: {
1559
+ type: 4,
1560
+ content: "",
1561
+ ast: {
1562
+ type: "ObjectExpression",
1563
+ properties: [property]
1564
+ }
1565
+ },
1566
+ modifiers: [],
1567
+ loc
1568
+ }];
1569
+ }
1570
+ default: return [];
1571
+ }
1572
+ }
1573
+ /** A compiler-core root with one component element per finding, in document order. */
1574
+ function toNuxtTemplateRoot(source, findings) {
1575
+ return {
1576
+ type: 0,
1577
+ source,
1578
+ children: findings.map((finding) => ({
1579
+ type: 1,
1580
+ tag: finding.tag,
1581
+ tagType: 1,
1582
+ props: findingProps(finding),
1583
+ children: [],
1584
+ loc: location(finding)
1585
+ }))
1586
+ };
1587
+ }
1588
+ /** Run a node transform on a root as Vue's `transform()` does: enter, then its exit callbacks. */
1589
+ function runNodeTransform(transform, root, context) {
1590
+ const exit = transform(root, context);
1591
+ for (const callback of Array.isArray(exit) ? exit : [exit]) if (typeof callback === "function") callback();
1592
+ }
1593
+ function mentionsCheckedTag(source, serverTags) {
1594
+ return ALWAYS_CHECKED_TAGS.some((tag) => source.includes(tag)) || serverTags.some((tag) => source.includes(tag));
1595
+ }
1596
+ /** Report Nuxt's template diagnostics for each SFC Vize compiles, per environment. */
1597
+ function createNuxtTemplateDiagnosticsBridge(options) {
1598
+ const readSource = options.readSource ?? ((file) => readFileSync(file, "utf8"));
1599
+ let finder;
1600
+ return {
1601
+ name: "vizejs:nuxt-template-diagnostics",
1602
+ enforce: "post",
1603
+ transform: {
1604
+ filter: { id: SFC_MODULE_ID },
1605
+ async handler(_code, id, transformOptions) {
1606
+ const transform = options.getTransform();
1607
+ if (!transform || !isVizeGeneratedVueModuleId(id)) return;
1608
+ const file = normalizeVizeGeneratedVueModuleId(id).split("?")[0];
1609
+ if (file.includes("/node_modules/")) return;
1610
+ let source;
1611
+ try {
1612
+ source = readSource(file);
1613
+ } catch {
1614
+ return;
1615
+ }
1616
+ const serverTags = options.getServerTags();
1617
+ const findings = mentionsCheckedTag(source, serverTags) ? (await (finder ||= options.loadFinder()))(source, serverTags) : [];
1618
+ const ssr = transformOptions?.ssr === true;
1619
+ try {
1620
+ runNodeTransform(transform, toNuxtTemplateRoot(source, findings), {
1621
+ filename: file,
1622
+ ssr,
1623
+ inSSR: ssr,
1624
+ bindingMetadata: {}
1625
+ });
1626
+ } catch {}
1627
+ }
1628
+ }
1629
+ };
1630
+ }
1631
+ /** Wire Nuxt's template diagnostics to the Vite plugins of a Vize-compiled app. */
1632
+ function setupNuxtTemplateDiagnostics(nuxt, plugins) {
1633
+ if (!nuxt.options.experimental?.templateDiagnostics) return;
1634
+ let transform;
1635
+ nuxt.hook("modules:done", () => {
1636
+ nuxt.hook("build:before", () => {
1637
+ transform = captureNuxtTemplateDiagnostics(nuxt.options);
1638
+ });
1639
+ });
1640
+ let components;
1641
+ let serverTags = [];
1642
+ plugins.push(createNuxtTemplateDiagnosticsBridge({
1643
+ getTransform: () => transform,
1644
+ getServerTags() {
1645
+ const current = nuxt.apps?.default?.components;
1646
+ if (current !== components) {
1647
+ components = current;
1648
+ serverTags = current ? resolveServerComponentTags(current) : [];
1649
+ }
1650
+ return serverTags;
1651
+ },
1652
+ async loadFinder() {
1653
+ return (await import("@vizejs/native")).nuxtTemplateDiagnostics ?? (() => []);
1654
+ }
1655
+ }));
1656
+ }
1657
+ //#endregion
1439
1658
  //#region src/vite-compiler.ts
1440
1659
  /**
1441
1660
  * Nuxt writes its generated root tsconfig to `typesDir` (Nuxt 4.7+), falling
@@ -1465,6 +1684,7 @@ async function setupNuxtViteCompiler(compilerOptions, nuxt, compiler) {
1465
1684
  ...nuxtTypeResolutionFallback(host)
1466
1685
  }, defaults, "nuxt");
1467
1686
  host.vite.plugins.push(plugins);
1687
+ setupNuxtTemplateDiagnostics(nuxt, host.vite.plugins);
1468
1688
  const stage = plugins.find((plugin) => plugin.name === "vite-plugin-vize:sfc");
1469
1689
  if (!stage) return;
1470
1690
  nuxt.hook("vite:configResolved", (config) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/nuxt",
3
- "version": "0.812.0",
3
+ "version": "0.814.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.812.0",
54
- "@vizejs/nuxt-lint-config": "0.812.0",
55
- "@vizejs/vite-plugin": "0.812.0",
56
- "@vizejs/vite-plugin-musea": "0.812.0",
57
- "vize": "0.812.0"
53
+ "@vizejs/native": "0.814.0",
54
+ "@vizejs/nuxt-lint-config": "0.814.0",
55
+ "@vizejs/vite-plugin": "0.814.0",
56
+ "@vizejs/vite-plugin-musea": "0.814.0",
57
+ "vize": "0.814.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.812.0",
62
+ "oxlint-plugin-vize": "0.814.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",
@@ -86,7 +86,8 @@
86
86
  "metadata": {
87
87
  "vize": {
88
88
  "stability": "compatibility-preview",
89
- "stabilityDocs": "https://github.com/ubugeeei-prod/vize/blob/main/docs/content/stability.md#package-support-tiers"
89
+ "stabilityDocs": "https://github.com/ubugeeei-prod/vize/blob/main/docs/content/stability.md#package-support-tiers",
90
+ "channel": "v1-alpha"
90
91
  }
91
92
  },
92
93
  "scripts": {