@designos/compiler-cli 0.1.1 → 0.3.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/cli.js CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/run.ts
4
- import { copyFile, lstat, mkdir, readFile, realpath, rename, rm, stat, writeFile } from "fs/promises";
4
+ import { copyFile, lstat, mkdir, readFile as readFile2, realpath as realpath2, rename, rm, stat as stat2, writeFile } from "fs/promises";
5
5
  import { randomUUID } from "crypto";
6
- import { dirname, isAbsolute, join, relative, resolve, sep } from "path";
6
+ import { dirname as dirname2, isAbsolute as isAbsolute2, join, relative as relative2, resolve as resolve2, sep as sep2 } from "path";
7
7
 
8
8
  // ../compiler-core/dist/index.js
9
9
  import {
@@ -1072,6 +1072,28 @@ function validateCompilerProject(project) {
1072
1072
  const componentTypes = /* @__PURE__ */ new Set();
1073
1073
  const componentNames = /* @__PURE__ */ new Set();
1074
1074
  const assetOutputs = /* @__PURE__ */ new Map();
1075
+ if (project.styles !== void 0 && !Array.isArray(project.styles)) {
1076
+ diagnostics.push({ severity: "error", code: "COMPILER_PROJECT_STYLES_INVALID", message: "styles must be an array", path: "styles" });
1077
+ }
1078
+ for (const [styleIndex, style] of (Array.isArray(project.styles) ? project.styles : []).entries()) {
1079
+ const stylePath = `styles[${styleIndex}]`;
1080
+ if (!isSafeRelativePath(style.source)) {
1081
+ diagnostics.push({ severity: "error", code: "COMPILER_PROJECT_STYLE_SOURCE_PATH_INVALID", message: "Style source must be a safe path relative to the project root", path: `${stylePath}.source` });
1082
+ continue;
1083
+ }
1084
+ const outputPath = style.outputPath ?? style.source;
1085
+ if (!isSafeRelativePath(outputPath)) {
1086
+ diagnostics.push({ severity: "error", code: "COMPILER_PROJECT_STYLE_OUTPUT_PATH_INVALID", message: "Style outputPath must be a safe path relative to the generated output directory", path: `${stylePath}.outputPath` });
1087
+ continue;
1088
+ }
1089
+ const normalizedOutputPath = outputPath.toLowerCase();
1090
+ const existingSource = assetOutputs.get(normalizedOutputPath);
1091
+ if (existingSource && existingSource !== style.source) {
1092
+ diagnostics.push({ severity: "error", code: "COMPILER_PROJECT_STYLE_OUTPUT_COLLISION", message: `Different styles target the same output path: ${outputPath}`, path: `${stylePath}.outputPath` });
1093
+ } else {
1094
+ assetOutputs.set(normalizedOutputPath, style.source);
1095
+ }
1096
+ }
1075
1097
  project.components.forEach((definition, index) => {
1076
1098
  const prefix = `components[${index}]`;
1077
1099
  const manifest = definition?.manifest;
@@ -1190,6 +1212,9 @@ async function compileProject(project, registry, options) {
1190
1212
  const generatedPaths = /* @__PURE__ */ new Set();
1191
1213
  const registryEntries = [];
1192
1214
  const targetDefinition = registry.get(options.target);
1215
+ for (const style of project.styles ?? []) {
1216
+ assets.set(style.outputPath ?? style.source, style.source);
1217
+ }
1193
1218
  for (const [index, definition] of project.components.entries()) {
1194
1219
  let result;
1195
1220
  if (definition.implementation.kind === "ir") {
@@ -1278,10 +1303,1900 @@ async function compileProject(project, registry, options) {
1278
1303
 
1279
1304
  // src/run.ts
1280
1305
  import { bladeTarget } from "@designos/compiler-blade";
1306
+
1307
+ // src/kit-validator.ts
1308
+ import { readFile, realpath, stat } from "fs/promises";
1309
+ import {
1310
+ dirname,
1311
+ extname,
1312
+ isAbsolute,
1313
+ relative,
1314
+ resolve,
1315
+ sep
1316
+ } from "path";
1317
+ import { parse as parseTypeScriptSource } from "@babel/parser";
1318
+ import Ajv2020 from "ajv/dist/2020.js";
1319
+ import addFormats from "ajv-formats";
1320
+ import semver from "semver";
1321
+ import {
1322
+ ComponentManifestSchema,
1323
+ validateComponentManifest
1324
+ } from "@designos/core";
1325
+
1326
+ // ../../schemas/designos.kit.schema.json
1327
+ var designos_kit_schema_default = {
1328
+ $schema: "https://json-schema.org/draft/2020-12/schema",
1329
+ $id: "https://raw.githubusercontent.com/relacloud/design-os/main/schemas/designos.kit.schema.json",
1330
+ title: "DesignOS Component Kit Manifest",
1331
+ description: "Root manifest for a version 1 DesignOS component kit.",
1332
+ type: "object",
1333
+ additionalProperties: false,
1334
+ required: [
1335
+ "schemaVersion",
1336
+ "id",
1337
+ "name",
1338
+ "version",
1339
+ "compilerProject",
1340
+ "designos",
1341
+ "components"
1342
+ ],
1343
+ properties: {
1344
+ $schema: {
1345
+ type: "string",
1346
+ format: "uri"
1347
+ },
1348
+ schemaVersion: {
1349
+ const: "1",
1350
+ description: "Version of this kit-manifest contract; independent from compiler project schemaVersion."
1351
+ },
1352
+ id: {
1353
+ type: "string",
1354
+ minLength: 1,
1355
+ maxLength: 214,
1356
+ pattern: "^(?:@[a-z0-9][a-z0-9._-]*/)?[a-z0-9][a-z0-9._-]*$",
1357
+ description: "Exact package identifier; semantic validation checks equality with package.json.name."
1358
+ },
1359
+ name: {
1360
+ type: "string",
1361
+ minLength: 1,
1362
+ maxLength: 160
1363
+ },
1364
+ version: {
1365
+ $ref: "#/$defs/semver",
1366
+ description: "Strict SemVer 2.0.0 package version; this value is not a compatibility range."
1367
+ },
1368
+ description: {
1369
+ type: "string",
1370
+ maxLength: 2e3
1371
+ },
1372
+ license: {
1373
+ type: "string",
1374
+ minLength: 1,
1375
+ maxLength: 128
1376
+ },
1377
+ compilerProject: {
1378
+ $ref: "#/$defs/packageRelativePath",
1379
+ description: "Package-relative path to the compiler project; existence and real-path containment are semantic checks."
1380
+ },
1381
+ designos: {
1382
+ type: "object",
1383
+ additionalProperties: false,
1384
+ required: ["kit"],
1385
+ properties: {
1386
+ kit: {
1387
+ type: "string",
1388
+ minLength: 1,
1389
+ description: "Non-empty SemVer range for the kit contract. Schema validation checks only the string; semantic validation parses the range."
1390
+ },
1391
+ core: {
1392
+ type: "string",
1393
+ minLength: 1,
1394
+ description: "Optional non-empty SemVer range for DesignOS core; semantic validation parses the range."
1395
+ },
1396
+ compiler: {
1397
+ type: "string",
1398
+ minLength: 1,
1399
+ description: "Optional non-empty SemVer range for the compiler; semantic validation parses the range."
1400
+ },
1401
+ editor: {
1402
+ type: "string",
1403
+ minLength: 1,
1404
+ description: "Optional non-empty SemVer range for the editor; semantic validation parses the range."
1405
+ }
1406
+ }
1407
+ },
1408
+ components: {
1409
+ type: "array",
1410
+ minItems: 1,
1411
+ items: {
1412
+ $ref: "#/$defs/component"
1413
+ }
1414
+ },
1415
+ editor: {
1416
+ type: "object",
1417
+ additionalProperties: false,
1418
+ properties: {
1419
+ catalog: {
1420
+ $ref: "#/$defs/packageRelativePath"
1421
+ },
1422
+ previews: {
1423
+ type: "object",
1424
+ description: "Optional editor host adapters keyed by stable component type.",
1425
+ propertyNames: {
1426
+ minLength: 1
1427
+ },
1428
+ additionalProperties: {
1429
+ $ref: "#/$defs/packageRelativePath"
1430
+ }
1431
+ }
1432
+ },
1433
+ minProperties: 1
1434
+ },
1435
+ metadata: {
1436
+ type: "object",
1437
+ description: "Reserved for non-normative publisher-specific metadata.",
1438
+ additionalProperties: true
1439
+ }
1440
+ },
1441
+ $defs: {
1442
+ component: {
1443
+ type: "object",
1444
+ additionalProperties: false,
1445
+ required: ["type", "source", "exportName", "manifest"],
1446
+ properties: {
1447
+ type: {
1448
+ type: "string",
1449
+ minLength: 1,
1450
+ maxLength: 128,
1451
+ description: "Stable public component type; uniqueness and manifest agreement are semantic checks."
1452
+ },
1453
+ source: {
1454
+ $ref: "#/$defs/packageRelativePath"
1455
+ },
1456
+ exportName: {
1457
+ type: "string",
1458
+ pattern: "^[A-Za-z_$][A-Za-z0-9_$]*$",
1459
+ description: "Compiler export identifier; agreement with the compiler-project entry is a semantic check."
1460
+ },
1461
+ manifest: {
1462
+ $ref: "#/$defs/packageRelativePath"
1463
+ }
1464
+ }
1465
+ },
1466
+ packageRelativePath: {
1467
+ type: "string",
1468
+ minLength: 1,
1469
+ maxLength: 1024,
1470
+ pattern: "^(?!/)(?![A-Za-z]:)(?!.*(?:^|/)\\.\\.?/)(?!.*(?:^|/)\\.\\.?$)[^\\\\\\u0000]+$",
1471
+ description: "Package-relative path with basic lexical restrictions. Semantic validation must check normalized segments, existence, and real-path containment after symlink resolution."
1472
+ },
1473
+ semver: {
1474
+ type: "string",
1475
+ pattern: "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(?:-((?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)(?:\\.(?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\\+([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?$",
1476
+ description: "Strict SemVer 2.0.0 version syntax, excluding compatibility ranges."
1477
+ }
1478
+ }
1479
+ };
1480
+
1481
+ // ../../schemas/designos.kit.schema.v2.json
1482
+ var designos_kit_schema_v2_default = {
1483
+ $schema: "https://json-schema.org/draft/2020-12/schema",
1484
+ $id: "https://raw.githubusercontent.com/relacloud/design-os/main/schemas/designos.kit.schema.v2.json",
1485
+ title: "DesignOS Component Kit Manifest (Version 2)",
1486
+ description: "Root manifest for a version 2 DesignOS component kit.",
1487
+ type: "object",
1488
+ additionalProperties: false,
1489
+ required: [
1490
+ "schemaVersion",
1491
+ "id",
1492
+ "name",
1493
+ "version",
1494
+ "compilerProject",
1495
+ "designos",
1496
+ "components",
1497
+ "design"
1498
+ ],
1499
+ properties: {
1500
+ $schema: {
1501
+ type: "string",
1502
+ format: "uri"
1503
+ },
1504
+ schemaVersion: {
1505
+ const: "2",
1506
+ description: "Version of this kit-manifest contract; independent from compiler project schemaVersion."
1507
+ },
1508
+ id: {
1509
+ type: "string",
1510
+ minLength: 1,
1511
+ maxLength: 214,
1512
+ pattern: "^(?:@[a-z0-9][a-z0-9._-]*/)?[a-z0-9][a-z0-9._-]*$",
1513
+ description: "Exact package identifier; semantic validation checks equality with package.json.name."
1514
+ },
1515
+ name: {
1516
+ type: "string",
1517
+ minLength: 1,
1518
+ maxLength: 160
1519
+ },
1520
+ version: {
1521
+ $ref: "#/$defs/semver",
1522
+ description: "Strict SemVer 2.0.0 package version; this value is not a compatibility range."
1523
+ },
1524
+ description: {
1525
+ type: "string",
1526
+ maxLength: 2e3
1527
+ },
1528
+ license: {
1529
+ type: "string",
1530
+ minLength: 1,
1531
+ maxLength: 128
1532
+ },
1533
+ compilerProject: {
1534
+ $ref: "#/$defs/packageRelativePath",
1535
+ description: "Package-relative path to the compiler project; existence and real-path containment are semantic checks."
1536
+ },
1537
+ design: {
1538
+ type: "object",
1539
+ additionalProperties: false,
1540
+ required: [
1541
+ "manifest"
1542
+ ],
1543
+ properties: {
1544
+ manifest: {
1545
+ $ref: "#/$defs/packageRelativePath",
1546
+ description: "Package-relative path to the kit design manifest."
1547
+ }
1548
+ },
1549
+ minProperties: 1
1550
+ },
1551
+ designos: {
1552
+ type: "object",
1553
+ additionalProperties: false,
1554
+ required: [
1555
+ "kit"
1556
+ ],
1557
+ properties: {
1558
+ kit: {
1559
+ type: "string",
1560
+ minLength: 1,
1561
+ description: "Non-empty SemVer range for the kit contract. Schema validation checks only the string; semantic validation parses the range."
1562
+ },
1563
+ core: {
1564
+ type: "string",
1565
+ minLength: 1,
1566
+ description: "Optional non-empty SemVer range for DesignOS core; semantic validation parses the range."
1567
+ },
1568
+ compiler: {
1569
+ type: "string",
1570
+ minLength: 1,
1571
+ description: "Optional non-empty SemVer range for the compiler; semantic validation parses the range."
1572
+ },
1573
+ editor: {
1574
+ type: "string",
1575
+ minLength: 1,
1576
+ description: "Optional non-empty SemVer range for the editor; semantic validation parses the range."
1577
+ }
1578
+ }
1579
+ },
1580
+ components: {
1581
+ type: "array",
1582
+ minItems: 1,
1583
+ items: {
1584
+ $ref: "#/$defs/component"
1585
+ }
1586
+ },
1587
+ editor: {
1588
+ type: "object",
1589
+ additionalProperties: false,
1590
+ properties: {
1591
+ catalog: {
1592
+ $ref: "#/$defs/packageRelativePath"
1593
+ },
1594
+ previews: {
1595
+ type: "object",
1596
+ description: "Optional editor host adapters keyed by stable component type.",
1597
+ propertyNames: {
1598
+ minLength: 1
1599
+ },
1600
+ additionalProperties: {
1601
+ $ref: "#/$defs/packageRelativePath"
1602
+ }
1603
+ }
1604
+ },
1605
+ minProperties: 1
1606
+ },
1607
+ metadata: {
1608
+ type: "object",
1609
+ description: "Reserved for non-normative publisher-specific metadata.",
1610
+ additionalProperties: true
1611
+ }
1612
+ },
1613
+ $defs: {
1614
+ component: {
1615
+ type: "object",
1616
+ additionalProperties: false,
1617
+ required: [
1618
+ "type",
1619
+ "source",
1620
+ "exportName",
1621
+ "manifest"
1622
+ ],
1623
+ properties: {
1624
+ type: {
1625
+ type: "string",
1626
+ minLength: 1,
1627
+ maxLength: 128,
1628
+ description: "Stable public component type; uniqueness and manifest agreement are semantic checks."
1629
+ },
1630
+ source: {
1631
+ $ref: "#/$defs/packageRelativePath"
1632
+ },
1633
+ exportName: {
1634
+ type: "string",
1635
+ pattern: "^[A-Za-z_$][A-Za-z0-9_$]*$",
1636
+ description: "Compiler export identifier; agreement with the compiler-project entry is a semantic check."
1637
+ },
1638
+ manifest: {
1639
+ $ref: "#/$defs/packageRelativePath"
1640
+ }
1641
+ }
1642
+ },
1643
+ packageRelativePath: {
1644
+ type: "string",
1645
+ minLength: 1,
1646
+ maxLength: 1024,
1647
+ pattern: "^(?!/)(?![A-Za-z]:)(?!.*(?:^|/)\\.\\.?/)(?!.*(?:^|/)\\.\\.?$)[^\\\\\\u0000]+$",
1648
+ description: "Package-relative path with basic lexical restrictions. Semantic validation must check normalized segments, existence, and real-path containment after symlink resolution."
1649
+ },
1650
+ semver: {
1651
+ type: "string",
1652
+ pattern: "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(?:-((?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)(?:\\.(?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\\+([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?$",
1653
+ description: "Strict SemVer 2.0.0 version syntax, excluding compatibility ranges."
1654
+ }
1655
+ }
1656
+ };
1657
+
1658
+ // ../../schemas/designos.design.schema.json
1659
+ var designos_design_schema_default = {
1660
+ $schema: "https://json-schema.org/draft/2020-12/schema",
1661
+ $id: "https://raw.githubusercontent.com/relacloud/design-os/main/schemas/designos.design.schema.json",
1662
+ title: "DesignOS Kit Design Manifest",
1663
+ description: "Declarative design tokens, defaults, and presets owned by a component kit.",
1664
+ type: "object",
1665
+ additionalProperties: false,
1666
+ required: ["schemaVersion", "name", "tokens", "presets"],
1667
+ properties: {
1668
+ $schema: {
1669
+ type: "string",
1670
+ format: "uri"
1671
+ },
1672
+ schemaVersion: {
1673
+ const: "1",
1674
+ description: "Version of the design-manifest format; independent from the kit-manifest and kit package versions."
1675
+ },
1676
+ name: {
1677
+ type: "string",
1678
+ minLength: 1,
1679
+ maxLength: 160
1680
+ },
1681
+ description: {
1682
+ type: "string",
1683
+ maxLength: 2e3
1684
+ },
1685
+ tokens: {
1686
+ type: "array",
1687
+ minItems: 1,
1688
+ items: {
1689
+ $ref: "#/$defs/token"
1690
+ }
1691
+ },
1692
+ presets: {
1693
+ type: "array",
1694
+ minItems: 1,
1695
+ items: {
1696
+ $ref: "#/$defs/preset"
1697
+ }
1698
+ }
1699
+ },
1700
+ $defs: {
1701
+ token: {
1702
+ type: "object",
1703
+ additionalProperties: false,
1704
+ required: ["id", "label", "type", "default", "cssVariable"],
1705
+ properties: {
1706
+ id: {
1707
+ type: "string",
1708
+ minLength: 1,
1709
+ maxLength: 128,
1710
+ pattern: "^[A-Za-z][A-Za-z0-9._-]*$",
1711
+ description: "Stable identifier used as the key in saved design values and preset values."
1712
+ },
1713
+ label: {
1714
+ type: "string",
1715
+ minLength: 1,
1716
+ maxLength: 160
1717
+ },
1718
+ description: {
1719
+ type: "string",
1720
+ maxLength: 1e3
1721
+ },
1722
+ group: {
1723
+ type: "string",
1724
+ minLength: 1,
1725
+ maxLength: 100
1726
+ },
1727
+ type: {
1728
+ enum: ["color", "font-family", "number", "select"]
1729
+ },
1730
+ default: {
1731
+ anyOf: [{ type: "string" }, { type: "number" }]
1732
+ },
1733
+ cssVariable: {
1734
+ type: "string",
1735
+ pattern: "^--[A-Za-z_][A-Za-z0-9_-]*$",
1736
+ description: "CSS custom property used when projecting the saved design into preview or runtime styles."
1737
+ },
1738
+ options: {
1739
+ type: "array",
1740
+ minItems: 1,
1741
+ items: {
1742
+ $ref: "#/$defs/option"
1743
+ }
1744
+ },
1745
+ min: {
1746
+ type: "number"
1747
+ },
1748
+ max: {
1749
+ type: "number"
1750
+ },
1751
+ step: {
1752
+ type: "number",
1753
+ exclusiveMinimum: 0
1754
+ },
1755
+ unit: {
1756
+ enum: ["", "px", "rem", "em", "%"]
1757
+ }
1758
+ },
1759
+ allOf: [
1760
+ {
1761
+ if: {
1762
+ properties: { type: { const: "color" } },
1763
+ required: ["type"]
1764
+ },
1765
+ then: {
1766
+ properties: {
1767
+ default: { $ref: "#/$defs/colorValue" }
1768
+ }
1769
+ }
1770
+ },
1771
+ {
1772
+ if: {
1773
+ properties: { type: { const: "font-family" } },
1774
+ required: ["type"]
1775
+ },
1776
+ then: {
1777
+ required: ["options"],
1778
+ properties: {
1779
+ default: { $ref: "#/$defs/fontFamilyValue" },
1780
+ options: {
1781
+ type: "array",
1782
+ minItems: 1,
1783
+ items: { $ref: "#/$defs/option" }
1784
+ }
1785
+ }
1786
+ }
1787
+ },
1788
+ {
1789
+ if: {
1790
+ properties: { type: { const: "number" } },
1791
+ required: ["type"]
1792
+ },
1793
+ then: {
1794
+ required: ["min", "max", "step"],
1795
+ properties: {
1796
+ default: { type: "number" },
1797
+ min: { type: "number" },
1798
+ max: { type: "number" },
1799
+ step: { type: "number", exclusiveMinimum: 0 }
1800
+ }
1801
+ }
1802
+ },
1803
+ {
1804
+ if: {
1805
+ properties: { type: { const: "select" } },
1806
+ required: ["type"]
1807
+ },
1808
+ then: {
1809
+ required: ["options"],
1810
+ properties: {
1811
+ default: { $ref: "#/$defs/optionValue" },
1812
+ options: {
1813
+ type: "array",
1814
+ minItems: 1,
1815
+ items: { $ref: "#/$defs/option" }
1816
+ }
1817
+ }
1818
+ }
1819
+ }
1820
+ ]
1821
+ },
1822
+ option: {
1823
+ type: "object",
1824
+ additionalProperties: false,
1825
+ required: ["value", "label"],
1826
+ properties: {
1827
+ value: {
1828
+ $ref: "#/$defs/optionValue"
1829
+ },
1830
+ label: {
1831
+ type: "string",
1832
+ minLength: 1,
1833
+ maxLength: 160
1834
+ }
1835
+ }
1836
+ },
1837
+ preset: {
1838
+ type: "object",
1839
+ additionalProperties: false,
1840
+ required: ["id", "name", "values"],
1841
+ properties: {
1842
+ id: {
1843
+ type: "string",
1844
+ minLength: 1,
1845
+ maxLength: 128,
1846
+ pattern: "^[A-Za-z][A-Za-z0-9._-]*$"
1847
+ },
1848
+ name: {
1849
+ type: "string",
1850
+ minLength: 1,
1851
+ maxLength: 160
1852
+ },
1853
+ description: {
1854
+ type: "string",
1855
+ maxLength: 1e3
1856
+ },
1857
+ values: {
1858
+ type: "object",
1859
+ minProperties: 1,
1860
+ additionalProperties: {
1861
+ anyOf: [{ type: "string" }, { type: "number" }]
1862
+ },
1863
+ description: "Values keyed by token ID. Semantic validation checks completeness and token compatibility."
1864
+ }
1865
+ }
1866
+ },
1867
+ colorValue: {
1868
+ type: "string",
1869
+ pattern: "^#(?:[A-Fa-f0-9]{3}|[A-Fa-f0-9]{4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$"
1870
+ },
1871
+ fontFamilyValue: {
1872
+ type: "string",
1873
+ minLength: 1,
1874
+ maxLength: 160,
1875
+ pattern: "^[A-Za-z0-9][A-Za-z0-9 _.,'-]*$"
1876
+ },
1877
+ optionValue: {
1878
+ type: "string",
1879
+ minLength: 1,
1880
+ maxLength: 160,
1881
+ pattern: "^[A-Za-z0-9][A-Za-z0-9 _.,'-]*$"
1882
+ }
1883
+ }
1884
+ };
1885
+
1886
+ // ../core/package.json
1887
+ var package_default = {
1888
+ name: "@designos/core",
1889
+ version: "0.2.0",
1890
+ private: false,
1891
+ type: "module",
1892
+ exports: {
1893
+ ".": {
1894
+ types: "./dist/index.d.ts",
1895
+ import: "./dist/index.js"
1896
+ }
1897
+ },
1898
+ scripts: {
1899
+ typecheck: "tsc --noEmit",
1900
+ build: "tsup",
1901
+ test: "vitest"
1902
+ },
1903
+ dependencies: {
1904
+ nanoid: "^5.1.6",
1905
+ zod: "^3.25.76"
1906
+ },
1907
+ devDependencies: {
1908
+ "@types/node": "^24.0.0",
1909
+ typescript: "^5.9.2",
1910
+ tsup: "^8.5.0",
1911
+ vitest: "^3.2.4"
1912
+ },
1913
+ files: [
1914
+ "dist",
1915
+ "README.md"
1916
+ ],
1917
+ main: "./dist/index.js",
1918
+ types: "./dist/index.d.ts",
1919
+ publishConfig: {
1920
+ access: "public"
1921
+ },
1922
+ repository: {
1923
+ type: "git",
1924
+ url: "git+https://github.com/relacloud/design-os.git",
1925
+ directory: "packages/core"
1926
+ }
1927
+ };
1928
+
1929
+ // package.json
1930
+ var package_default2 = {
1931
+ name: "@designos/compiler-cli",
1932
+ version: "0.3.0",
1933
+ private: false,
1934
+ type: "module",
1935
+ bin: {
1936
+ designos: "./dist/cli.js"
1937
+ },
1938
+ files: [
1939
+ "dist",
1940
+ "README.md"
1941
+ ],
1942
+ engines: {
1943
+ node: ">=20"
1944
+ },
1945
+ scripts: {
1946
+ build: "tsup",
1947
+ typecheck: "tsc --noEmit",
1948
+ test: "vitest run"
1949
+ },
1950
+ dependencies: {
1951
+ "@babel/parser": "^7.28.4",
1952
+ "@builder.io/mitosis": "0.14.1",
1953
+ "@designos/compiler-blade": "workspace:*",
1954
+ "@designos/compiler-core": "workspace:*",
1955
+ "@designos/core": "workspace:^",
1956
+ ajv: "^8.17.1",
1957
+ "ajv-formats": "^3.0.1",
1958
+ semver: "^7.7.2"
1959
+ },
1960
+ devDependencies: {
1961
+ "@types/node": "^24.0.0",
1962
+ "@types/semver": "^7.7.0",
1963
+ tsup: "^8.5.0",
1964
+ typescript: "^5.9.2",
1965
+ vitest: "^3.2.4"
1966
+ },
1967
+ main: "./dist/cli.js",
1968
+ publishConfig: {
1969
+ access: "public"
1970
+ },
1971
+ repository: {
1972
+ type: "git",
1973
+ url: "git+https://github.com/relacloud/design-os.git",
1974
+ directory: "packages/compiler-cli"
1975
+ }
1976
+ };
1977
+
1978
+ // src/kit-validator.ts
1979
+ var schemaValidators = (() => {
1980
+ const ajv = new Ajv2020({ allErrors: true, strict: true });
1981
+ addFormats(ajv);
1982
+ return {
1983
+ "1": ajv.compile(designos_kit_schema_default),
1984
+ "2": ajv.compile(designos_kit_schema_v2_default),
1985
+ design: ajv.compile(designos_design_schema_default)
1986
+ };
1987
+ })();
1988
+ var CURRENT_TOOL_VERSIONS = {
1989
+ core: package_default.version,
1990
+ compiler: package_default2.version
1991
+ };
1992
+ function isRecord(value) {
1993
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
1994
+ }
1995
+ function collectSourceImports(sourceText) {
1996
+ const ast = parseTypeScriptSource(sourceText, {
1997
+ sourceType: "module",
1998
+ plugins: ["typescript", "jsx"]
1999
+ });
2000
+ const importPaths = /* @__PURE__ */ new Set();
2001
+ const visit = (value) => {
2002
+ if (Array.isArray(value)) {
2003
+ for (const item of value) visit(item);
2004
+ return;
2005
+ }
2006
+ if (!isRecord(value)) return;
2007
+ const source = value.source;
2008
+ if ((value.type === "ImportDeclaration" || value.type === "ExportNamedDeclaration" || value.type === "ExportAllDeclaration") && isRecord(source) && typeof source.value === "string") {
2009
+ importPaths.add(source.value);
2010
+ }
2011
+ if (value.type === "ImportExpression" && isRecord(source) && typeof source.value === "string") {
2012
+ importPaths.add(source.value);
2013
+ }
2014
+ if (value.type === "CallExpression" && Array.isArray(value.arguments)) {
2015
+ const callee = value.callee;
2016
+ const isImport = isRecord(callee) && callee.type === "Import";
2017
+ const isRequire = isRecord(callee) && callee.type === "Identifier" && callee.name === "require";
2018
+ const firstArgument = value.arguments[0];
2019
+ if ((isImport || isRequire) && isRecord(firstArgument) && typeof firstArgument.value === "string") {
2020
+ importPaths.add(firstArgument.value);
2021
+ }
2022
+ }
2023
+ for (const [key, nested] of Object.entries(value)) {
2024
+ if ([
2025
+ "loc",
2026
+ "start",
2027
+ "end",
2028
+ "extra",
2029
+ "comments",
2030
+ "leadingComments",
2031
+ "trailingComments",
2032
+ "innerComments"
2033
+ ].includes(key))
2034
+ continue;
2035
+ visit(nested);
2036
+ }
2037
+ };
2038
+ visit(ast.program);
2039
+ return [...importPaths];
2040
+ }
2041
+ function isWithin(root, candidate) {
2042
+ const pathFromRoot = relative(root, candidate);
2043
+ return pathFromRoot === "" || pathFromRoot !== ".." && !pathFromRoot.startsWith(`..${sep}`) && !isAbsolute(pathFromRoot);
2044
+ }
2045
+ function isSafeRelativePath2(value) {
2046
+ return typeof value === "string" && value.length > 0 && !value.startsWith("/") && !value.includes("\\") && !value.includes("\0") && !/^[A-Za-z]:/.test(value) && value.split("/").every(
2047
+ (segment) => segment.length > 0 && segment !== "." && segment !== ".."
2048
+ );
2049
+ }
2050
+ function addError(diagnostics, code, message, path) {
2051
+ diagnostics.push({
2052
+ severity: "error",
2053
+ code,
2054
+ message,
2055
+ ...path ? { path } : {}
2056
+ });
2057
+ }
2058
+ async function readJsonFile(path, displayPath, diagnostics) {
2059
+ let text;
2060
+ try {
2061
+ text = await readFile(path, "utf8");
2062
+ } catch (cause) {
2063
+ addError(
2064
+ diagnostics,
2065
+ "KIT_FILE_READ_FAILED",
2066
+ `Unable to read ${displayPath}: ${cause instanceof Error ? cause.message : String(cause)}`,
2067
+ displayPath
2068
+ );
2069
+ return void 0;
2070
+ }
2071
+ try {
2072
+ return JSON.parse(text);
2073
+ } catch (cause) {
2074
+ addError(
2075
+ diagnostics,
2076
+ "KIT_JSON_INVALID",
2077
+ `Invalid JSON in ${displayPath}: ${cause instanceof Error ? cause.message : String(cause)}`,
2078
+ displayPath
2079
+ );
2080
+ return void 0;
2081
+ }
2082
+ }
2083
+ async function resolveRootFile(rootRealPath, pathValue, displayPath, diagnostics) {
2084
+ if (!isSafeRelativePath2(pathValue)) {
2085
+ addError(
2086
+ diagnostics,
2087
+ "KIT_PATH_INVALID",
2088
+ "Expected a normalized package-relative path without traversal, absolute segments, or backslashes.",
2089
+ displayPath
2090
+ );
2091
+ return void 0;
2092
+ }
2093
+ const candidate = resolve(rootRealPath, pathValue);
2094
+ if (!isWithin(rootRealPath, candidate)) {
2095
+ addError(
2096
+ diagnostics,
2097
+ "KIT_PATH_ESCAPES_ROOT",
2098
+ "Path resolves outside the kit package root.",
2099
+ displayPath
2100
+ );
2101
+ return void 0;
2102
+ }
2103
+ return resolveExistingFile(rootRealPath, candidate, displayPath, diagnostics);
2104
+ }
2105
+ async function resolveNestedFile(rootRealPath, baseDirectory, pathValue, displayPath, diagnostics) {
2106
+ if (typeof pathValue !== "string" || pathValue.length === 0 || pathValue.includes("\\") || pathValue.includes("\0") || pathValue.startsWith("/") || /^[A-Za-z]:/.test(pathValue)) {
2107
+ addError(
2108
+ diagnostics,
2109
+ "KIT_ADAPTER_PATH_INVALID",
2110
+ "Expected a relative adapter reference without an absolute path or backslashes.",
2111
+ displayPath
2112
+ );
2113
+ return void 0;
2114
+ }
2115
+ const candidate = resolve(baseDirectory, pathValue);
2116
+ if (!isWithin(rootRealPath, candidate)) {
2117
+ addError(
2118
+ diagnostics,
2119
+ "KIT_PATH_ESCAPES_ROOT",
2120
+ "Adapter reference resolves outside the kit package root.",
2121
+ displayPath
2122
+ );
2123
+ return void 0;
2124
+ }
2125
+ return resolveExistingFile(rootRealPath, candidate, displayPath, diagnostics);
2126
+ }
2127
+ async function resolveExistingFile(rootRealPath, candidate, displayPath, diagnostics) {
2128
+ let candidateRealPath;
2129
+ try {
2130
+ candidateRealPath = await realpath(candidate);
2131
+ } catch (cause) {
2132
+ addError(
2133
+ diagnostics,
2134
+ "KIT_FILE_NOT_FOUND",
2135
+ `Referenced file does not exist or cannot be resolved: ${cause instanceof Error ? cause.message : String(cause)}`,
2136
+ displayPath
2137
+ );
2138
+ return void 0;
2139
+ }
2140
+ if (!isWithin(rootRealPath, candidateRealPath)) {
2141
+ addError(
2142
+ diagnostics,
2143
+ "KIT_PATH_SYMLINK_ESCAPE",
2144
+ "Referenced path resolves through a symlink outside the kit package root.",
2145
+ displayPath
2146
+ );
2147
+ return void 0;
2148
+ }
2149
+ try {
2150
+ const info = await stat(candidateRealPath);
2151
+ if (!info.isFile()) {
2152
+ addError(
2153
+ diagnostics,
2154
+ "KIT_FILE_NOT_REGULAR",
2155
+ "Referenced path must resolve to a regular file.",
2156
+ displayPath
2157
+ );
2158
+ return void 0;
2159
+ }
2160
+ } catch (cause) {
2161
+ addError(
2162
+ diagnostics,
2163
+ "KIT_FILE_STAT_FAILED",
2164
+ `Unable to inspect referenced file: ${cause instanceof Error ? cause.message : String(cause)}`,
2165
+ displayPath
2166
+ );
2167
+ return void 0;
2168
+ }
2169
+ return candidateRealPath;
2170
+ }
2171
+ function validateCompatibility(manifest, diagnostics) {
2172
+ for (const [name, range] of Object.entries(manifest.designos)) {
2173
+ if (typeof range !== "string" || range.trim().length === 0 || semver.validRange(range) === null) {
2174
+ addError(
2175
+ diagnostics,
2176
+ "KIT_COMPATIBILITY_RANGE_INVALID",
2177
+ `Invalid SemVer compatibility range: ${JSON.stringify(range)}.`,
2178
+ `designos.${name}`
2179
+ );
2180
+ continue;
2181
+ }
2182
+ const currentVersion = name === "kit" ? manifest.schemaVersion === "2" ? "2.0.0" : "1.0.0" : CURRENT_TOOL_VERSIONS[name];
2183
+ if (!currentVersion && name === "editor") {
2184
+ diagnostics.push({
2185
+ severity: "info",
2186
+ code: "KIT_COMPATIBILITY_VERSION_UNAVAILABLE",
2187
+ path: `designos.${name}`,
2188
+ message: "The editor compatibility range is syntactically valid, but this CLI has no current editor version to compare against."
2189
+ });
2190
+ }
2191
+ if (currentVersion && !semver.satisfies(currentVersion, range)) {
2192
+ diagnostics.push({
2193
+ severity: "warning",
2194
+ code: "KIT_COMPATIBILITY_MISMATCH",
2195
+ path: `designos.${name}`,
2196
+ message: `Declared range ${JSON.stringify(range)} does not include the current ${name} version ${currentVersion}.`
2197
+ });
2198
+ }
2199
+ }
2200
+ }
2201
+ function convertCompilerDiagnostic(diagnostic) {
2202
+ return {
2203
+ severity: diagnostic.severity,
2204
+ code: diagnostic.code,
2205
+ message: diagnostic.message,
2206
+ ...diagnostic.path ? { path: `compilerProject.${diagnostic.path}` } : {}
2207
+ };
2208
+ }
2209
+ function validateSemverPackageVersion(version, path, diagnostics) {
2210
+ if (typeof version !== "string" || semver.valid(version, { loose: false }) !== version) {
2211
+ addError(
2212
+ diagnostics,
2213
+ "KIT_PACKAGE_VERSION_INVALID",
2214
+ "Package version must be a strict SemVer 2.0.0 version.",
2215
+ path
2216
+ );
2217
+ }
2218
+ }
2219
+ async function validateEditorAdapters(rootRealPath, manifest, components, diagnostics) {
2220
+ const editor = manifest.editor;
2221
+ if (!editor) return;
2222
+ const componentsByType = new Map(
2223
+ components.map((component) => [component.definition.type, component])
2224
+ );
2225
+ const previewPaths = /* @__PURE__ */ new Map();
2226
+ for (const [type, pathValue] of Object.entries(editor.previews ?? {})) {
2227
+ if (!componentsByType.has(type)) {
2228
+ addError(
2229
+ diagnostics,
2230
+ "KIT_EDITOR_PREVIEW_TYPE_UNKNOWN",
2231
+ `Editor preview is declared for unknown component type ${JSON.stringify(type)}.`,
2232
+ `editor.previews.${type}`
2233
+ );
2234
+ }
2235
+ const previewPath = await resolveRootFile(
2236
+ rootRealPath,
2237
+ pathValue,
2238
+ `editor.previews.${type}`,
2239
+ diagnostics
2240
+ );
2241
+ if (previewPath) previewPaths.set(type, previewPath);
2242
+ }
2243
+ if (!editor.catalog) return;
2244
+ const catalogRealPath = await resolveRootFile(
2245
+ rootRealPath,
2246
+ editor.catalog,
2247
+ "editor.catalog",
2248
+ diagnostics
2249
+ );
2250
+ if (!catalogRealPath) return;
2251
+ const catalogValue = await readJsonFile(
2252
+ catalogRealPath,
2253
+ editor.catalog,
2254
+ diagnostics
2255
+ );
2256
+ if (!isRecord(catalogValue)) {
2257
+ addError(
2258
+ diagnostics,
2259
+ "KIT_EDITOR_CATALOG_INVALID",
2260
+ "Editor catalog must be a JSON object.",
2261
+ "editor.catalog"
2262
+ );
2263
+ return;
2264
+ }
2265
+ if (catalogValue.schemaVersion !== "1") {
2266
+ addError(
2267
+ diagnostics,
2268
+ "KIT_EDITOR_CATALOG_SCHEMA_VERSION_UNSUPPORTED",
2269
+ 'Editor catalog schemaVersion must be "1".',
2270
+ "editor.catalog.schemaVersion"
2271
+ );
2272
+ }
2273
+ if (!Array.isArray(catalogValue.components)) {
2274
+ addError(
2275
+ diagnostics,
2276
+ "KIT_EDITOR_CATALOG_COMPONENTS_INVALID",
2277
+ "Editor catalog components must be an array.",
2278
+ "editor.catalog.components"
2279
+ );
2280
+ return;
2281
+ }
2282
+ const catalogBase = dirname(resolve(rootRealPath, editor.catalog));
2283
+ const seenTypes = /* @__PURE__ */ new Set();
2284
+ const catalogPreviewTypes = /* @__PURE__ */ new Set();
2285
+ for (const [index, value] of catalogValue.components.entries()) {
2286
+ const prefix = `editor.catalog.components[${index}]`;
2287
+ if (!isRecord(value) || typeof value.type !== "string" || typeof value.manifest !== "string") {
2288
+ addError(
2289
+ diagnostics,
2290
+ "KIT_EDITOR_CATALOG_ENTRY_INVALID",
2291
+ "Catalog entry requires string type and manifest fields.",
2292
+ prefix
2293
+ );
2294
+ continue;
2295
+ }
2296
+ const { type } = value;
2297
+ if (seenTypes.has(type))
2298
+ addError(
2299
+ diagnostics,
2300
+ "KIT_EDITOR_CATALOG_TYPE_DUPLICATE",
2301
+ `Duplicate editor catalog component type ${JSON.stringify(type)}.`,
2302
+ `${prefix}.type`
2303
+ );
2304
+ seenTypes.add(type);
2305
+ const kitComponent = componentsByType.get(type);
2306
+ if (!kitComponent) {
2307
+ addError(
2308
+ diagnostics,
2309
+ "KIT_EDITOR_CATALOG_TYPE_UNKNOWN",
2310
+ `Editor catalog references unknown component type ${JSON.stringify(type)}.`,
2311
+ `${prefix}.type`
2312
+ );
2313
+ }
2314
+ const catalogManifest = await resolveNestedFile(
2315
+ rootRealPath,
2316
+ catalogBase,
2317
+ value.manifest,
2318
+ `${prefix}.manifest`,
2319
+ diagnostics
2320
+ );
2321
+ if (catalogManifest && kitComponent?.manifestPath && catalogManifest !== kitComponent.manifestPath) {
2322
+ addError(
2323
+ diagnostics,
2324
+ "KIT_EDITOR_CATALOG_MANIFEST_MISMATCH",
2325
+ "Catalog manifest reference does not identify the kit inventory manifest for this component type.",
2326
+ `${prefix}.manifest`
2327
+ );
2328
+ }
2329
+ if (value.preview !== void 0) {
2330
+ if (typeof value.preview !== "string") {
2331
+ addError(
2332
+ diagnostics,
2333
+ "KIT_EDITOR_CATALOG_PREVIEW_INVALID",
2334
+ "Catalog preview reference must be a string.",
2335
+ `${prefix}.preview`
2336
+ );
2337
+ continue;
2338
+ }
2339
+ catalogPreviewTypes.add(type);
2340
+ const preview = await resolveNestedFile(
2341
+ rootRealPath,
2342
+ catalogBase,
2343
+ value.preview,
2344
+ `${prefix}.preview`,
2345
+ diagnostics
2346
+ );
2347
+ const declaredPreview = previewPaths.get(type);
2348
+ if (!declaredPreview) {
2349
+ addError(
2350
+ diagnostics,
2351
+ "KIT_EDITOR_PREVIEW_UNDECLARED",
2352
+ "Catalog preview must also be declared in designos.kit.json editor.previews.",
2353
+ `${prefix}.preview`
2354
+ );
2355
+ } else if (preview && preview !== declaredPreview) {
2356
+ addError(
2357
+ diagnostics,
2358
+ "KIT_EDITOR_PREVIEW_MISMATCH",
2359
+ "Catalog preview reference does not match editor.previews for this component type.",
2360
+ `${prefix}.preview`
2361
+ );
2362
+ }
2363
+ } else if (previewPaths.has(type)) {
2364
+ addError(
2365
+ diagnostics,
2366
+ "KIT_EDITOR_PREVIEW_MISSING_FROM_CATALOG",
2367
+ "The kit declares a preview for this component but the catalog entry omits it.",
2368
+ `${prefix}.preview`
2369
+ );
2370
+ }
2371
+ }
2372
+ for (const type of previewPaths.keys()) {
2373
+ if (!catalogPreviewTypes.has(type)) {
2374
+ addError(
2375
+ diagnostics,
2376
+ "KIT_EDITOR_PREVIEW_NOT_IN_CATALOG",
2377
+ `Declared editor preview for ${JSON.stringify(type)} is not referenced by the catalog.`,
2378
+ `editor.previews.${type}`
2379
+ );
2380
+ }
2381
+ }
2382
+ }
2383
+ function isValidDesignValue(token, value) {
2384
+ switch (token.type) {
2385
+ case "color":
2386
+ return typeof value === "string" && /^#(?:[A-Fa-f0-9]{3}|[A-Fa-f0-9]{4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/.test(
2387
+ value
2388
+ );
2389
+ case "font-family":
2390
+ case "select":
2391
+ return typeof value === "string" && (token.options ?? []).some((option) => option.value === value);
2392
+ case "number":
2393
+ return typeof value === "number" && Number.isFinite(value) && token.min !== void 0 && token.max !== void 0 && token.step !== void 0 && token.step > 0 && value >= token.min && value <= token.max && Math.abs(
2394
+ (value - token.min) / token.step - Math.round((value - token.min) / token.step)
2395
+ ) < 1e-9;
2396
+ }
2397
+ }
2398
+ function validateDesignSemantics(design, diagnostics) {
2399
+ const tokensById = /* @__PURE__ */ new Map();
2400
+ const tokenIds = /* @__PURE__ */ new Set();
2401
+ const cssVariables = /* @__PURE__ */ new Set();
2402
+ for (const [index, token] of design.tokens.entries()) {
2403
+ const path = `design.tokens[${index}]`;
2404
+ if (tokenIds.has(token.id)) {
2405
+ addError(
2406
+ diagnostics,
2407
+ "KIT_DESIGN_TOKEN_ID_DUPLICATE",
2408
+ `Duplicate design token ID ${JSON.stringify(token.id)}.`,
2409
+ `${path}.id`
2410
+ );
2411
+ } else {
2412
+ tokenIds.add(token.id);
2413
+ tokensById.set(token.id, token);
2414
+ }
2415
+ if (cssVariables.has(token.cssVariable)) {
2416
+ addError(
2417
+ diagnostics,
2418
+ "KIT_DESIGN_CSS_VARIABLE_DUPLICATE",
2419
+ `CSS variable ${JSON.stringify(token.cssVariable)} is assigned to more than one design token.`,
2420
+ `${path}.cssVariable`
2421
+ );
2422
+ }
2423
+ cssVariables.add(token.cssVariable);
2424
+ if (token.type === "number" && token.min > token.max) {
2425
+ addError(
2426
+ diagnostics,
2427
+ "KIT_DESIGN_NUMBER_RANGE_INVALID",
2428
+ "Numeric token minimum must not exceed its maximum.",
2429
+ `${path}.min`
2430
+ );
2431
+ }
2432
+ const optionValues = /* @__PURE__ */ new Set();
2433
+ for (const [optionIndex, option] of (token.options ?? []).entries()) {
2434
+ if (optionValues.has(option.value)) {
2435
+ addError(
2436
+ diagnostics,
2437
+ "KIT_DESIGN_OPTION_VALUE_DUPLICATE",
2438
+ `Duplicate option value ${JSON.stringify(option.value)} for token ${JSON.stringify(token.id)}.`,
2439
+ `${path}.options[${optionIndex}].value`
2440
+ );
2441
+ }
2442
+ optionValues.add(option.value);
2443
+ }
2444
+ if (!isValidDesignValue(token, token.default)) {
2445
+ addError(
2446
+ diagnostics,
2447
+ "KIT_DESIGN_DEFAULT_INVALID",
2448
+ `Default value is not valid for ${token.type} token ${JSON.stringify(token.id)}.`,
2449
+ `${path}.default`
2450
+ );
2451
+ }
2452
+ }
2453
+ const presetIds = /* @__PURE__ */ new Set();
2454
+ for (const [index, preset] of design.presets.entries()) {
2455
+ const path = `design.presets[${index}]`;
2456
+ if (presetIds.has(preset.id)) {
2457
+ addError(
2458
+ diagnostics,
2459
+ "KIT_DESIGN_PRESET_ID_DUPLICATE",
2460
+ `Duplicate design preset ID ${JSON.stringify(preset.id)}.`,
2461
+ `${path}.id`
2462
+ );
2463
+ }
2464
+ presetIds.add(preset.id);
2465
+ for (const token of tokensById.values()) {
2466
+ if (!Object.hasOwn(preset.values, token.id)) {
2467
+ addError(
2468
+ diagnostics,
2469
+ "KIT_DESIGN_PRESET_VALUE_MISSING",
2470
+ `Preset ${JSON.stringify(preset.id)} must define a value for token ${JSON.stringify(token.id)}.`,
2471
+ `${path}.values.${token.id}`
2472
+ );
2473
+ } else if (!isValidDesignValue(token, preset.values[token.id])) {
2474
+ addError(
2475
+ diagnostics,
2476
+ "KIT_DESIGN_PRESET_VALUE_INVALID",
2477
+ `Preset value is not valid for ${token.type} token ${JSON.stringify(token.id)}.`,
2478
+ `${path}.values.${token.id}`
2479
+ );
2480
+ }
2481
+ }
2482
+ for (const tokenId of Object.keys(preset.values)) {
2483
+ if (!tokensById.has(tokenId)) {
2484
+ addError(
2485
+ diagnostics,
2486
+ "KIT_DESIGN_PRESET_VALUE_UNKNOWN",
2487
+ `Preset ${JSON.stringify(preset.id)} references unknown token ${JSON.stringify(tokenId)}.`,
2488
+ `${path}.values.${tokenId}`
2489
+ );
2490
+ }
2491
+ }
2492
+ }
2493
+ }
2494
+ async function validateDesignManifest(rootRealPath, manifest, diagnostics) {
2495
+ if (manifest.schemaVersion !== "2" || !manifest.design) return;
2496
+ const designPath = await resolveRootFile(
2497
+ rootRealPath,
2498
+ manifest.design.manifest,
2499
+ "design.manifest",
2500
+ diagnostics
2501
+ );
2502
+ if (!designPath) return;
2503
+ const designValue = await readJsonFile(
2504
+ designPath,
2505
+ manifest.design.manifest,
2506
+ diagnostics
2507
+ );
2508
+ if (designValue === void 0) return;
2509
+ if (!schemaValidators.design(designValue)) {
2510
+ for (const error of schemaValidators.design.errors ?? []) {
2511
+ diagnostics.push({
2512
+ severity: "error",
2513
+ code: "KIT_DESIGN_MANIFEST_SCHEMA_INVALID",
2514
+ path: `design.manifest${error.instancePath || ""}`,
2515
+ message: `${error.message ?? "Schema constraint failed"}${error.params ? ` (${JSON.stringify(error.params)})` : ""}`
2516
+ });
2517
+ }
2518
+ return;
2519
+ }
2520
+ validateDesignSemantics(
2521
+ designValue,
2522
+ diagnostics
2523
+ );
2524
+ }
2525
+ async function validateComponentKit(kitRoot) {
2526
+ const diagnostics = [];
2527
+ let rootRealPath;
2528
+ try {
2529
+ rootRealPath = await realpath(resolve(kitRoot));
2530
+ const rootInfo = await stat(rootRealPath);
2531
+ if (!rootInfo.isDirectory()) throw new Error("Kit root is not a directory");
2532
+ } catch (cause) {
2533
+ addError(
2534
+ diagnostics,
2535
+ "KIT_ROOT_INVALID",
2536
+ `Unable to access kit root: ${cause instanceof Error ? cause.message : String(cause)}`,
2537
+ "."
2538
+ );
2539
+ return { valid: false, diagnostics };
2540
+ }
2541
+ const manifestCandidate = resolve(rootRealPath, "designos.kit.json");
2542
+ const manifestPath = await resolveExistingFile(
2543
+ rootRealPath,
2544
+ manifestCandidate,
2545
+ "designos.kit.json",
2546
+ diagnostics
2547
+ );
2548
+ if (!manifestPath) return { valid: false, diagnostics };
2549
+ const rawManifest = await readJsonFile(
2550
+ manifestPath,
2551
+ "designos.kit.json",
2552
+ diagnostics
2553
+ );
2554
+ if (rawManifest === void 0) return { valid: false, diagnostics };
2555
+ const rawSchemaVersion = isRecord(rawManifest) ? rawManifest.schemaVersion : void 0;
2556
+ if (typeof rawSchemaVersion === "string" && rawSchemaVersion !== "1" && rawSchemaVersion !== "2") {
2557
+ addError(
2558
+ diagnostics,
2559
+ "KIT_SCHEMA_VERSION_UNSUPPORTED",
2560
+ `Unsupported kit schemaVersion ${JSON.stringify(rawSchemaVersion)}; supported versions are "1" and "2".`,
2561
+ "schemaVersion"
2562
+ );
2563
+ return { valid: false, diagnostics };
2564
+ }
2565
+ const schemaValidator = rawSchemaVersion === "2" ? schemaValidators["2"] : schemaValidators["1"];
2566
+ if (!schemaValidator(rawManifest)) {
2567
+ for (const error of schemaValidator.errors ?? []) {
2568
+ diagnostics.push({
2569
+ severity: "error",
2570
+ code: "KIT_MANIFEST_SCHEMA_INVALID",
2571
+ path: error.instancePath || "$",
2572
+ message: `${error.message ?? "Schema constraint failed"}${error.params ? ` (${JSON.stringify(error.params)})` : ""}`
2573
+ });
2574
+ }
2575
+ return { valid: false, diagnostics };
2576
+ }
2577
+ const manifest = rawManifest;
2578
+ validateCompatibility(manifest, diagnostics);
2579
+ await validateDesignManifest(rootRealPath, manifest, diagnostics);
2580
+ const packageCandidate = resolve(rootRealPath, "package.json");
2581
+ const packagePath = await resolveExistingFile(
2582
+ rootRealPath,
2583
+ packageCandidate,
2584
+ "package.json",
2585
+ diagnostics
2586
+ );
2587
+ const packageValue = packagePath ? await readJsonFile(packagePath, "package.json", diagnostics) : void 0;
2588
+ if (!isRecord(packageValue)) {
2589
+ if (packageValue !== void 0)
2590
+ addError(
2591
+ diagnostics,
2592
+ "KIT_PACKAGE_JSON_INVALID",
2593
+ "Root package.json must be a JSON object.",
2594
+ "package.json"
2595
+ );
2596
+ } else {
2597
+ if (packageValue.name !== manifest.id) {
2598
+ addError(
2599
+ diagnostics,
2600
+ "KIT_PACKAGE_NAME_MISMATCH",
2601
+ `package.json name ${JSON.stringify(packageValue.name)} must exactly match kit id ${JSON.stringify(manifest.id)}.`,
2602
+ "package.json.name"
2603
+ );
2604
+ }
2605
+ if (packageValue.version !== manifest.version) {
2606
+ addError(
2607
+ diagnostics,
2608
+ "KIT_PACKAGE_VERSION_MISMATCH",
2609
+ `package.json version ${JSON.stringify(packageValue.version)} must exactly match kit version ${JSON.stringify(manifest.version)}.`,
2610
+ "package.json.version"
2611
+ );
2612
+ }
2613
+ validateSemverPackageVersion(
2614
+ packageValue.version,
2615
+ "package.json.version",
2616
+ diagnostics
2617
+ );
2618
+ }
2619
+ const rootComponents = [];
2620
+ const seenTypes = /* @__PURE__ */ new Set();
2621
+ const seenSources = /* @__PURE__ */ new Set();
2622
+ const seenManifests = /* @__PURE__ */ new Set();
2623
+ for (const [index, component] of manifest.components.entries()) {
2624
+ const prefix = `components[${index}]`;
2625
+ if (seenTypes.has(component.type))
2626
+ addError(
2627
+ diagnostics,
2628
+ "KIT_COMPONENT_TYPE_DUPLICATE",
2629
+ `Duplicate component type ${JSON.stringify(component.type)}.`,
2630
+ `${prefix}.type`
2631
+ );
2632
+ seenTypes.add(component.type);
2633
+ const sourcePath = await resolveRootFile(
2634
+ rootRealPath,
2635
+ component.source,
2636
+ `${prefix}.source`,
2637
+ diagnostics
2638
+ );
2639
+ const manifestPathValue = await resolveRootFile(
2640
+ rootRealPath,
2641
+ component.manifest,
2642
+ `${prefix}.manifest`,
2643
+ diagnostics
2644
+ );
2645
+ if (sourcePath) {
2646
+ if (seenSources.has(sourcePath))
2647
+ addError(
2648
+ diagnostics,
2649
+ "KIT_COMPONENT_SOURCE_DUPLICATE",
2650
+ "Multiple kit inventory entries resolve to the same source file.",
2651
+ `${prefix}.source`
2652
+ );
2653
+ seenSources.add(sourcePath);
2654
+ }
2655
+ if (manifestPathValue) {
2656
+ if (seenManifests.has(manifestPathValue))
2657
+ addError(
2658
+ diagnostics,
2659
+ "KIT_COMPONENT_MANIFEST_DUPLICATE",
2660
+ "Multiple kit inventory entries resolve to the same component manifest.",
2661
+ `${prefix}.manifest`
2662
+ );
2663
+ seenManifests.add(manifestPathValue);
2664
+ }
2665
+ rootComponents.push({
2666
+ definition: component,
2667
+ sourcePath,
2668
+ manifestPath: manifestPathValue
2669
+ });
2670
+ }
2671
+ const compilerProjectPath = await resolveRootFile(
2672
+ rootRealPath,
2673
+ manifest.compilerProject,
2674
+ "compilerProject",
2675
+ diagnostics
2676
+ );
2677
+ if (!compilerProjectPath) return { valid: false, diagnostics };
2678
+ const rawProject = await readJsonFile(
2679
+ compilerProjectPath,
2680
+ manifest.compilerProject,
2681
+ diagnostics
2682
+ );
2683
+ if (!isRecord(rawProject)) {
2684
+ if (rawProject !== void 0)
2685
+ addError(
2686
+ diagnostics,
2687
+ "KIT_COMPILER_PROJECT_INVALID",
2688
+ "Compiler project must be a JSON object.",
2689
+ "compilerProject"
2690
+ );
2691
+ return { valid: false, diagnostics };
2692
+ }
2693
+ if (rawProject.schemaVersion !== "2") {
2694
+ addError(
2695
+ diagnostics,
2696
+ "KIT_COMPILER_PROJECT_SCHEMA_VERSION_UNSUPPORTED",
2697
+ 'Component-kit inventory requires a file-based compiler project with schemaVersion "2".',
2698
+ "compilerProject.schemaVersion"
2699
+ );
2700
+ return { valid: false, diagnostics };
2701
+ }
2702
+ const sourceProject = rawProject;
2703
+ if (!Array.isArray(sourceProject.components)) {
2704
+ addError(
2705
+ diagnostics,
2706
+ "KIT_COMPILER_PROJECT_COMPONENTS_INVALID",
2707
+ "Compiler project components must be an array.",
2708
+ "compilerProject.components"
2709
+ );
2710
+ return { valid: false, diagnostics };
2711
+ }
2712
+ const projectComponents = [];
2713
+ const seenProjectSources = /* @__PURE__ */ new Set();
2714
+ const seenProjectManifests = /* @__PURE__ */ new Set();
2715
+ const compilerComponents = [];
2716
+ const projectStyles = [];
2717
+ const declaredStylePaths = /* @__PURE__ */ new Set();
2718
+ const declaredAssetPaths = /* @__PURE__ */ new Set();
2719
+ const declaredOutputPaths = /* @__PURE__ */ new Map();
2720
+ if (sourceProject.styles !== void 0 && !Array.isArray(sourceProject.styles)) {
2721
+ addError(
2722
+ diagnostics,
2723
+ "KIT_COMPILER_PROJECT_STYLES_INVALID",
2724
+ "Compiler project styles must be an array.",
2725
+ "compilerProject.styles"
2726
+ );
2727
+ }
2728
+ for (const [index, style] of (Array.isArray(sourceProject.styles) ? sourceProject.styles : []).entries()) {
2729
+ const parsed = await validateProjectAsset(
2730
+ rootRealPath,
2731
+ style,
2732
+ `compilerProject.styles[${index}]`,
2733
+ diagnostics,
2734
+ declaredStylePaths,
2735
+ declaredOutputPaths
2736
+ );
2737
+ if (parsed) projectStyles.push(parsed);
2738
+ }
2739
+ for (const [index, entry] of sourceProject.components.entries()) {
2740
+ const prefix = `compilerProject.components[${index}]`;
2741
+ if (!isRecord(entry)) {
2742
+ addError(
2743
+ diagnostics,
2744
+ "KIT_COMPILER_PROJECT_COMPONENT_INVALID",
2745
+ "Compiler project component entry must be an object.",
2746
+ prefix
2747
+ );
2748
+ projectComponents.push({});
2749
+ continue;
2750
+ }
2751
+ const sourcePath = await resolveRootFile(
2752
+ rootRealPath,
2753
+ entry.source,
2754
+ `${prefix}.source`,
2755
+ diagnostics
2756
+ );
2757
+ const componentManifestPath = await resolveRootFile(
2758
+ rootRealPath,
2759
+ entry.manifest,
2760
+ `${prefix}.manifest`,
2761
+ diagnostics
2762
+ );
2763
+ if (sourcePath) {
2764
+ if (seenProjectSources.has(sourcePath))
2765
+ addError(
2766
+ diagnostics,
2767
+ "KIT_PROJECT_SOURCE_DUPLICATE",
2768
+ "Multiple compiler project entries resolve to the same source file.",
2769
+ `${prefix}.source`
2770
+ );
2771
+ seenProjectSources.add(sourcePath);
2772
+ }
2773
+ if (componentManifestPath) {
2774
+ if (seenProjectManifests.has(componentManifestPath))
2775
+ addError(
2776
+ diagnostics,
2777
+ "KIT_PROJECT_MANIFEST_DUPLICATE",
2778
+ "Multiple compiler project entries resolve to the same manifest file.",
2779
+ `${prefix}.manifest`
2780
+ );
2781
+ seenProjectManifests.add(componentManifestPath);
2782
+ }
2783
+ if (entry.exportName !== void 0 && typeof entry.exportName !== "string") {
2784
+ addError(
2785
+ diagnostics,
2786
+ "KIT_PROJECT_EXPORT_NAME_INVALID",
2787
+ "Compiler project exportName must be a string when provided.",
2788
+ `${prefix}.exportName`
2789
+ );
2790
+ }
2791
+ let manifestType;
2792
+ let parsedManifest;
2793
+ if (componentManifestPath) {
2794
+ const value = await readJsonFile(
2795
+ componentManifestPath,
2796
+ String(entry.manifest),
2797
+ diagnostics
2798
+ );
2799
+ if (value !== void 0) {
2800
+ const result = ComponentManifestSchema.safeParse(value);
2801
+ if (!result.success) {
2802
+ for (const issue of result.error.issues) {
2803
+ addError(
2804
+ diagnostics,
2805
+ "KIT_COMPONENT_MANIFEST_INVALID",
2806
+ `${issue.path.join(".") || "manifest"}: ${issue.message}`,
2807
+ `${prefix}.manifest`
2808
+ );
2809
+ }
2810
+ } else {
2811
+ parsedManifest = result.data;
2812
+ manifestType = parsedManifest.type;
2813
+ for (const issue of validateComponentManifest(parsedManifest).issues) {
2814
+ addError(
2815
+ diagnostics,
2816
+ "KIT_COMPONENT_MANIFEST_SEMANTIC_INVALID",
2817
+ issue.message,
2818
+ `${prefix}.manifest.${issue.path}`
2819
+ );
2820
+ }
2821
+ }
2822
+ }
2823
+ }
2824
+ let implementation;
2825
+ let sourceImports = [];
2826
+ if (sourcePath && typeof entry.source === "string") {
2827
+ if (!entry.source.endsWith(".lite.tsx")) {
2828
+ addError(
2829
+ diagnostics,
2830
+ "KIT_COMPONENT_SOURCE_EXTENSION_INVALID",
2831
+ "Compiler source files must use the .lite.tsx extension.",
2832
+ `${prefix}.source`
2833
+ );
2834
+ }
2835
+ try {
2836
+ const sourceText = await readFile(sourcePath, "utf8");
2837
+ try {
2838
+ sourceImports = collectSourceImports(sourceText);
2839
+ } catch (cause) {
2840
+ addError(
2841
+ diagnostics,
2842
+ "KIT_SOURCE_IMPORT_SCAN_FAILED",
2843
+ `Unable to inspect source imports: ${cause instanceof Error ? cause.message : String(cause)}`,
2844
+ `${prefix}.source`
2845
+ );
2846
+ }
2847
+ const component = parseMitosisSource(sourceText, {
2848
+ filePath: entry.source,
2849
+ enableBlocksSlots: true
2850
+ });
2851
+ implementation = { kind: "mitosis", component };
2852
+ if (typeof entry.exportName === "string" && component.name !== entry.exportName) {
2853
+ addError(
2854
+ diagnostics,
2855
+ "KIT_PROJECT_EXPORT_NAME_MISMATCH",
2856
+ `exportName ${JSON.stringify(entry.exportName)} does not match parsed component name ${JSON.stringify(component.name)}.`,
2857
+ `${prefix}.exportName`
2858
+ );
2859
+ }
2860
+ } catch (cause) {
2861
+ addError(
2862
+ diagnostics,
2863
+ "KIT_COMPONENT_SOURCE_INVALID",
2864
+ `Unable to parse compiler source: ${cause instanceof Error ? cause.message : String(cause)}`,
2865
+ `${prefix}.source`
2866
+ );
2867
+ }
2868
+ }
2869
+ const styles = [];
2870
+ if (entry.styles !== void 0 && !Array.isArray(entry.styles)) {
2871
+ addError(
2872
+ diagnostics,
2873
+ "KIT_PROJECT_STYLES_INVALID",
2874
+ "Component styles must be an array.",
2875
+ `${prefix}.styles`
2876
+ );
2877
+ }
2878
+ for (const [styleIndex, style] of (Array.isArray(entry.styles) ? entry.styles : []).entries()) {
2879
+ const parsed = await validateProjectAsset(
2880
+ rootRealPath,
2881
+ style,
2882
+ `${prefix}.styles[${styleIndex}]`,
2883
+ diagnostics,
2884
+ declaredStylePaths,
2885
+ declaredOutputPaths
2886
+ );
2887
+ if (parsed) styles.push(parsed);
2888
+ }
2889
+ const assets = [];
2890
+ if (entry.assets !== void 0 && !Array.isArray(entry.assets)) {
2891
+ addError(
2892
+ diagnostics,
2893
+ "KIT_PROJECT_ASSETS_INVALID",
2894
+ "Component assets must be an array.",
2895
+ `${prefix}.assets`
2896
+ );
2897
+ }
2898
+ for (const [assetIndex, asset] of (Array.isArray(entry.assets) ? entry.assets : []).entries()) {
2899
+ const parsed = await validateProjectAsset(
2900
+ rootRealPath,
2901
+ asset,
2902
+ `${prefix}.assets[${assetIndex}]`,
2903
+ diagnostics,
2904
+ declaredAssetPaths,
2905
+ declaredOutputPaths
2906
+ );
2907
+ if (parsed) assets.push(parsed);
2908
+ }
2909
+ if (sourcePath && implementation?.kind === "mitosis") {
2910
+ await validateLocalImports(
2911
+ rootRealPath,
2912
+ dirname(sourcePath),
2913
+ sourceImports,
2914
+ declaredStylePaths,
2915
+ declaredAssetPaths,
2916
+ prefix,
2917
+ diagnostics
2918
+ );
2919
+ }
2920
+ const outputDirectory = entry.outputDirectory;
2921
+ if (outputDirectory !== void 0 && typeof outputDirectory !== "string") {
2922
+ addError(
2923
+ diagnostics,
2924
+ "KIT_PROJECT_OUTPUT_DIRECTORY_INVALID",
2925
+ "outputDirectory must be a string when provided.",
2926
+ `${prefix}.outputDirectory`
2927
+ );
2928
+ }
2929
+ if (parsedManifest && implementation) {
2930
+ const sourceDirectory = typeof entry.source === "string" ? dirname(entry.source).split(sep).join("/") : ".";
2931
+ const component = {
2932
+ manifest: parsedManifest,
2933
+ implementation,
2934
+ outputDirectory: typeof outputDirectory === "string" ? outputDirectory : sourceDirectory === "." ? "components" : sourceDirectory,
2935
+ styles,
2936
+ assets
2937
+ };
2938
+ compilerComponents.push(component);
2939
+ }
2940
+ projectComponents.push({
2941
+ source: sourcePath,
2942
+ manifest: componentManifestPath,
2943
+ exportName: typeof entry.exportName === "string" ? entry.exportName : void 0,
2944
+ manifestType
2945
+ });
2946
+ }
2947
+ for (const [outputPath, pathOwner] of declaredOutputPaths) {
2948
+ const nestedOutput = [...declaredOutputPaths.keys()].find(
2949
+ (candidate) => candidate.startsWith(`${outputPath}/`)
2950
+ );
2951
+ if (nestedOutput) {
2952
+ addError(
2953
+ diagnostics,
2954
+ "KIT_OUTPUT_PATH_FILE_DIRECTORY_CONFLICT",
2955
+ `Output path ${JSON.stringify(outputPath)} is also used as a directory prefix for ${JSON.stringify(nestedOutput)}.`,
2956
+ `${pathOwner}.outputPath`
2957
+ );
2958
+ }
2959
+ }
2960
+ const rootComponentsByType = new Map(
2961
+ rootComponents.map((component) => [component.definition.type, component])
2962
+ );
2963
+ const projectTypes = /* @__PURE__ */ new Set();
2964
+ for (const [index, projectComponent] of projectComponents.entries()) {
2965
+ const type = projectComponent.manifestType;
2966
+ if (!type) continue;
2967
+ if (projectTypes.has(type))
2968
+ addError(
2969
+ diagnostics,
2970
+ "KIT_PROJECT_COMPONENT_TYPE_DUPLICATE",
2971
+ `Duplicate compiler project component type ${JSON.stringify(type)}.`,
2972
+ `compilerProject.components[${index}].manifest`
2973
+ );
2974
+ projectTypes.add(type);
2975
+ const kitComponent = rootComponentsByType.get(type);
2976
+ if (!kitComponent) {
2977
+ addError(
2978
+ diagnostics,
2979
+ "KIT_PROJECT_COMPONENT_NOT_IN_INVENTORY",
2980
+ `Compiler project component type ${JSON.stringify(type)} is missing from the kit inventory.`,
2981
+ `compilerProject.components[${index}]`
2982
+ );
2983
+ continue;
2984
+ }
2985
+ if (projectComponent.source && kitComponent.sourcePath && projectComponent.source !== kitComponent.sourcePath) {
2986
+ addError(
2987
+ diagnostics,
2988
+ "KIT_COMPONENT_SOURCE_MISMATCH",
2989
+ `Compiler project source for ${JSON.stringify(type)} does not match the package-relative inventory source.`,
2990
+ `compilerProject.components[${index}].source`
2991
+ );
2992
+ }
2993
+ if (projectComponent.manifest && kitComponent.manifestPath && projectComponent.manifest !== kitComponent.manifestPath) {
2994
+ addError(
2995
+ diagnostics,
2996
+ "KIT_COMPONENT_MANIFEST_MISMATCH",
2997
+ `Compiler project manifest for ${JSON.stringify(type)} does not match the package-relative inventory manifest.`,
2998
+ `compilerProject.components[${index}].manifest`
2999
+ );
3000
+ }
3001
+ if (projectComponent.exportName !== kitComponent.definition.exportName) {
3002
+ addError(
3003
+ diagnostics,
3004
+ "KIT_COMPONENT_EXPORT_NAME_MISMATCH",
3005
+ `Compiler project exportName for ${JSON.stringify(type)} must match the kit inventory.`,
3006
+ `compilerProject.components[${index}].exportName`
3007
+ );
3008
+ }
3009
+ }
3010
+ for (const [index, component] of rootComponents.entries()) {
3011
+ if (!projectTypes.has(component.definition.type)) {
3012
+ addError(
3013
+ diagnostics,
3014
+ "KIT_INVENTORY_COMPONENT_NOT_IN_PROJECT",
3015
+ `Kit inventory component type ${JSON.stringify(component.definition.type)} is missing from the compiler project.`,
3016
+ `components[${index}]`
3017
+ );
3018
+ }
3019
+ }
3020
+ if (projectComponents.length !== rootComponents.length) {
3021
+ addError(
3022
+ diagnostics,
3023
+ "KIT_INVENTORY_PROJECT_COMPONENT_COUNT_MISMATCH",
3024
+ `Kit inventory has ${rootComponents.length} components, but compiler project has ${projectComponents.length}.`,
3025
+ "components"
3026
+ );
3027
+ }
3028
+ const compilerProject = {
3029
+ schemaVersion: "1",
3030
+ components: compilerComponents,
3031
+ styles: projectStyles
3032
+ };
3033
+ for (const diagnostic of validateCompilerProject(compilerProject)) {
3034
+ diagnostics.push(convertCompilerDiagnostic(diagnostic));
3035
+ }
3036
+ await validateEditorAdapters(
3037
+ rootRealPath,
3038
+ manifest,
3039
+ rootComponents,
3040
+ diagnostics
3041
+ );
3042
+ return {
3043
+ valid: !diagnostics.some((diagnostic) => diagnostic.severity === "error"),
3044
+ diagnostics
3045
+ };
3046
+ }
3047
+ async function validateProjectAsset(rootRealPath, value, displayPath, diagnostics, declaredPaths, declaredOutputPaths) {
3048
+ if (!isRecord(value) || typeof value.source !== "string") {
3049
+ addError(
3050
+ diagnostics,
3051
+ "KIT_PROJECT_ASSET_INVALID",
3052
+ "Asset reference requires a project-relative source path.",
3053
+ displayPath
3054
+ );
3055
+ return void 0;
3056
+ }
3057
+ const sourcePath = await resolveRootFile(
3058
+ rootRealPath,
3059
+ value.source,
3060
+ `${displayPath}.source`,
3061
+ diagnostics
3062
+ );
3063
+ let outputPath;
3064
+ if (value.outputPath !== void 0) {
3065
+ if (!isSafeRelativePath2(value.outputPath)) {
3066
+ addError(
3067
+ diagnostics,
3068
+ "KIT_PROJECT_ASSET_OUTPUT_PATH_INVALID",
3069
+ "Asset outputPath must be a normalized relative path.",
3070
+ `${displayPath}.outputPath`
3071
+ );
3072
+ } else {
3073
+ outputPath = value.outputPath;
3074
+ }
3075
+ }
3076
+ if (!sourcePath) return void 0;
3077
+ declaredPaths?.add(sourcePath);
3078
+ const effectiveOutputPath = outputPath ?? value.source;
3079
+ const outputKey = effectiveOutputPath.toLowerCase();
3080
+ const existingOutput = declaredOutputPaths?.get(outputKey);
3081
+ if (existingOutput) {
3082
+ addError(
3083
+ diagnostics,
3084
+ "KIT_OUTPUT_PATH_DUPLICATE",
3085
+ `Output path ${JSON.stringify(effectiveOutputPath)} is already declared by ${existingOutput}.`,
3086
+ `${displayPath}.outputPath`
3087
+ );
3088
+ } else {
3089
+ declaredOutputPaths?.set(outputKey, displayPath);
3090
+ }
3091
+ return { source: value.source, ...outputPath ? { outputPath } : {} };
3092
+ }
3093
+ async function validateLocalImports(rootRealPath, sourceDirectory, imports, declaredStyles, declaredAssets, componentPath, diagnostics) {
3094
+ for (const [index, importEntry] of imports.entries()) {
3095
+ const importPath = importEntry;
3096
+ if (!importPath.startsWith(".")) {
3097
+ if (isAbsolute(importPath) || /^[A-Za-z]:/.test(importPath)) {
3098
+ addError(
3099
+ diagnostics,
3100
+ "KIT_SOURCE_IMPORT_ABSOLUTE_INVALID",
3101
+ "Local source imports must not use absolute filesystem paths.",
3102
+ `${componentPath}.source.imports[${index}]`
3103
+ );
3104
+ }
3105
+ continue;
3106
+ }
3107
+ const candidates = [importPath];
3108
+ if (!extname(importPath)) {
3109
+ candidates.push(
3110
+ `${importPath}.lite.tsx`,
3111
+ `${importPath}.tsx`,
3112
+ `${importPath}.ts`,
3113
+ `${importPath}.jsx`,
3114
+ `${importPath}.js`,
3115
+ `${importPath}.css`
3116
+ );
3117
+ }
3118
+ let resolvedImport;
3119
+ let escapedRoot = false;
3120
+ for (const candidatePath of candidates) {
3121
+ const candidate = resolve(sourceDirectory, candidatePath);
3122
+ if (!isWithin(rootRealPath, candidate)) {
3123
+ escapedRoot = true;
3124
+ addError(
3125
+ diagnostics,
3126
+ "KIT_SOURCE_IMPORT_ESCAPES_ROOT",
3127
+ "Local source import resolves outside the kit package root.",
3128
+ `${componentPath}.source.imports[${index}]`
3129
+ );
3130
+ break;
3131
+ }
3132
+ try {
3133
+ const candidateRealPath = await realpath(candidate);
3134
+ if (!isWithin(rootRealPath, candidateRealPath)) {
3135
+ escapedRoot = true;
3136
+ addError(
3137
+ diagnostics,
3138
+ "KIT_SOURCE_IMPORT_SYMLINK_ESCAPE",
3139
+ "Local source import resolves through a symlink outside the kit package root.",
3140
+ `${componentPath}.source.imports[${index}]`
3141
+ );
3142
+ break;
3143
+ }
3144
+ if ((await stat(candidateRealPath)).isFile()) {
3145
+ resolvedImport = candidateRealPath;
3146
+ break;
3147
+ }
3148
+ } catch {
3149
+ }
3150
+ }
3151
+ if (!resolvedImport) {
3152
+ if (!escapedRoot) {
3153
+ addError(
3154
+ diagnostics,
3155
+ "KIT_SOURCE_IMPORT_NOT_FOUND",
3156
+ `Local source import ${JSON.stringify(importPath)} does not resolve to a file inside the kit package.`,
3157
+ `${componentPath}.source.imports[${index}]`
3158
+ );
3159
+ }
3160
+ continue;
3161
+ }
3162
+ const extension = extname(resolvedImport).toLowerCase();
3163
+ if (extension === ".css" && !declaredStyles.has(resolvedImport)) {
3164
+ addError(
3165
+ diagnostics,
3166
+ "KIT_LOCAL_STYLE_UNDECLARED",
3167
+ `Imported stylesheet ${JSON.stringify(importPath)} must be declared in compiler-project styles.`,
3168
+ `${componentPath}.source.imports[${index}]`
3169
+ );
3170
+ }
3171
+ if ([
3172
+ ".avif",
3173
+ ".gif",
3174
+ ".jpeg",
3175
+ ".jpg",
3176
+ ".png",
3177
+ ".svg",
3178
+ ".webp",
3179
+ ".woff",
3180
+ ".woff2",
3181
+ ".ttf",
3182
+ ".otf"
3183
+ ].includes(extension) && !declaredAssets.has(resolvedImport)) {
3184
+ addError(
3185
+ diagnostics,
3186
+ "KIT_LOCAL_ASSET_UNDECLARED",
3187
+ `Imported asset ${JSON.stringify(importPath)} must be declared in compiler-project assets.`,
3188
+ `${componentPath}.source.imports[${index}]`
3189
+ );
3190
+ }
3191
+ }
3192
+ }
3193
+
3194
+ // src/run.ts
1281
3195
  var HELP = `DesignOS compiler CLI
1282
3196
 
1283
3197
  Usage:
1284
3198
  designos compile --target <target> [options]
3199
+ designos kit validate [--root <directory>]
1285
3200
 
1286
3201
  Options:
1287
3202
  --target <target> Registered target name (for example react or vue)
@@ -1291,6 +3206,48 @@ Options:
1291
3206
  --target-option key=value Pass a target-specific option; repeatable, values parse as JSON
1292
3207
  --help Show this help
1293
3208
  `;
3209
+ var KIT_HELP = `DesignOS component-kit validator
3210
+
3211
+ Usage:
3212
+ designos kit validate [--root <directory>]
3213
+
3214
+ Options:
3215
+ --root <directory> Kit package root (default: current directory)
3216
+ --help Show this help
3217
+
3218
+ Validation is read-only and does not compile a target or write artifacts.
3219
+ `;
3220
+ function parseKitArguments(args) {
3221
+ if (args.length === 0 || args[0] === "--help" || args[0] === "help") return { help: true };
3222
+ if (args[0] !== "validate") throw new Error(`Unknown kit command: ${args[0]}
3223
+
3224
+ ${KIT_HELP}`);
3225
+ const options = {};
3226
+ for (let index = 1; index < args.length; index += 1) {
3227
+ const flag = args[index];
3228
+ if (flag === "--help") return { help: true };
3229
+ if (flag !== "--root") throw new Error(`Unknown option: ${flag}
3230
+
3231
+ ${KIT_HELP}`);
3232
+ const value = args[index + 1];
3233
+ if (!value || value.startsWith("--")) throw new Error(`Missing value for ${flag}`);
3234
+ options.root = value;
3235
+ index += 1;
3236
+ }
3237
+ return options;
3238
+ }
3239
+ async function runKitCommand(args, output, cwd) {
3240
+ const parsed = parseKitArguments(args);
3241
+ if ("help" in parsed) {
3242
+ output.log(KIT_HELP);
3243
+ return 0;
3244
+ }
3245
+ const result = await validateComponentKit(resolve2(cwd, parsed.root ?? "."));
3246
+ printDiagnostics(output, result.diagnostics);
3247
+ if (!result.valid) return 1;
3248
+ output.log("Component kit validation passed. No target compilation or output generation was run.");
3249
+ return 0;
3250
+ }
1294
3251
  function parseTargetOption(value) {
1295
3252
  const separator = value.indexOf("=");
1296
3253
  if (separator < 1) throw new Error(`Invalid --target-option ${JSON.stringify(value)}; expected key=value`);
@@ -1335,16 +3292,16 @@ ${HELP}`);
1335
3292
  if (!options.target) throw new Error("Missing required --target option");
1336
3293
  return options;
1337
3294
  }
1338
- function isWithin(root, candidate) {
1339
- const pathFromRoot = relative(root, candidate);
1340
- return pathFromRoot === "" || pathFromRoot !== ".." && !pathFromRoot.startsWith(`..${sep}`) && !isAbsolute(pathFromRoot);
3295
+ function isWithin2(root, candidate) {
3296
+ const pathFromRoot = relative2(root, candidate);
3297
+ return pathFromRoot === "" || pathFromRoot !== ".." && !pathFromRoot.startsWith(`..${sep2}`) && !isAbsolute2(pathFromRoot);
1341
3298
  }
1342
- function isSafeRelativePath2(value) {
3299
+ function isSafeRelativePath3(value) {
1343
3300
  return value.length > 0 && !value.startsWith("/") && !value.includes("\\") && !/^[A-Za-z]:/.test(value) && value.split("/").every((segment) => segment.length > 0 && segment !== "." && segment !== "..");
1344
3301
  }
1345
3302
  async function ensureDirectoryWithoutSymlinks(root, relativeDirectory) {
1346
3303
  let current = root;
1347
- for (const segment of relativeDirectory ? relativeDirectory.split(sep).filter(Boolean) : []) {
3304
+ for (const segment of relativeDirectory ? relativeDirectory.split(sep2).filter(Boolean) : []) {
1348
3305
  current = join(current, segment);
1349
3306
  try {
1350
3307
  const entry = await lstat(current);
@@ -1359,28 +3316,28 @@ async function ensureDirectoryWithoutSymlinks(root, relativeDirectory) {
1359
3316
  return current;
1360
3317
  }
1361
3318
  async function prepareOutputRoot(projectRoot, outputArgument) {
1362
- const distPath = resolve(projectRoot, "dist");
1363
- const requestedOutput = resolve(projectRoot, outputArgument);
1364
- if (requestedOutput === distPath || !isWithin(distPath, requestedOutput)) {
3319
+ const distPath = resolve2(projectRoot, "dist");
3320
+ const requestedOutput = resolve2(projectRoot, outputArgument);
3321
+ if (requestedOutput === distPath || !isWithin2(distPath, requestedOutput)) {
1365
3322
  throw new Error("--out-dir must be a dedicated subdirectory inside the project dist directory");
1366
3323
  }
1367
3324
  await mkdir(distPath, { recursive: true });
1368
- const rootRealPath = await realpath(projectRoot);
1369
- const distRealPath = await realpath(distPath);
1370
- if (!isWithin(rootRealPath, distRealPath)) throw new Error("The project dist directory resolves outside the project root");
1371
- const relativeOutput = relative(distPath, requestedOutput);
1372
- if (!relativeOutput || relativeOutput === ".." || relativeOutput.startsWith(`..${sep}`) || isAbsolute(relativeOutput)) {
3325
+ const rootRealPath = await realpath2(projectRoot);
3326
+ const distRealPath = await realpath2(distPath);
3327
+ if (!isWithin2(rootRealPath, distRealPath)) throw new Error("The project dist directory resolves outside the project root");
3328
+ const relativeOutput = relative2(distPath, requestedOutput);
3329
+ if (!relativeOutput || relativeOutput === ".." || relativeOutput.startsWith(`..${sep2}`) || isAbsolute2(relativeOutput)) {
1373
3330
  throw new Error("--out-dir must resolve to a subdirectory inside dist");
1374
3331
  }
1375
3332
  return ensureDirectoryWithoutSymlinks(distRealPath, relativeOutput);
1376
3333
  }
1377
3334
  async function resolveProjectAsset(projectRoot, projectRootReal, source) {
1378
- if (!isSafeRelativePath2(source)) throw new Error(`Asset source is not a safe project-relative path: ${source}`);
1379
- const candidate = resolve(projectRoot, source);
1380
- if (!isWithin(projectRoot, candidate)) throw new Error(`Asset source escapes project root: ${source}`);
1381
- const sourceRealPath = await realpath(candidate);
1382
- if (!isWithin(projectRootReal, sourceRealPath)) throw new Error(`Asset source resolves outside project root: ${source}`);
1383
- const info = await stat(sourceRealPath);
3335
+ if (!isSafeRelativePath3(source)) throw new Error(`Asset source is not a safe project-relative path: ${source}`);
3336
+ const candidate = resolve2(projectRoot, source);
3337
+ if (!isWithin2(projectRoot, candidate)) throw new Error(`Asset source escapes project root: ${source}`);
3338
+ const sourceRealPath = await realpath2(candidate);
3339
+ if (!isWithin2(projectRootReal, sourceRealPath)) throw new Error(`Asset source resolves outside project root: ${source}`);
3340
+ const info = await stat2(sourceRealPath);
1384
3341
  if (!info.isFile()) throw new Error(`Asset source is not a file: ${source}`);
1385
3342
  return sourceRealPath;
1386
3343
  }
@@ -1391,6 +3348,14 @@ async function loadCompilerProject(config, projectRoot, projectRootReal) {
1391
3348
  if (schemaVersion !== "2") throw new Error(`Unsupported project schemaVersion ${JSON.stringify(schemaVersion)}; expected "1" (IR) or "2" (TSX source)`);
1392
3349
  const sourceProject = config;
1393
3350
  if (!Array.isArray(sourceProject.components)) throw new Error("Source project components must be an array");
3351
+ if (!Array.isArray(sourceProject.styles ?? [])) throw new Error("Source project styles must be an array");
3352
+ const styles = await Promise.all((sourceProject.styles ?? []).map(async (style, index) => {
3353
+ if (!style || typeof style.source !== "string" || style.outputPath !== void 0 && typeof style.outputPath !== "string") {
3354
+ throw new Error(`styles[${index}] requires a project-relative source and optional outputPath`);
3355
+ }
3356
+ await resolveProjectAsset(projectRoot, projectRootReal, style.source);
3357
+ return style;
3358
+ }));
1394
3359
  const components = await Promise.all(sourceProject.components.map(async (entry, index) => {
1395
3360
  const prefix = `components[${index}]`;
1396
3361
  if (!entry || typeof entry.source !== "string" || typeof entry.manifest !== "string") {
@@ -1403,11 +3368,11 @@ async function loadCompilerProject(config, projectRoot, projectRootReal) {
1403
3368
  const manifestPath = await resolveProjectAsset(projectRoot, projectRootReal, entry.manifest);
1404
3369
  let manifest;
1405
3370
  try {
1406
- manifest = JSON.parse(await readFile(manifestPath, "utf8"));
3371
+ manifest = JSON.parse(await readFile2(manifestPath, "utf8"));
1407
3372
  } catch (cause) {
1408
3373
  throw new Error(`Unable to read JSON manifest ${entry.manifest}: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
1409
3374
  }
1410
- const source = await readFile(sourcePath, "utf8");
3375
+ const source = await readFile2(sourcePath, "utf8");
1411
3376
  const implementation = parseMitosisSource(source, { filePath: entry.source, enableBlocksSlots: true });
1412
3377
  if (entry.exportName && implementation.name !== entry.exportName) {
1413
3378
  throw new Error(`${prefix}.exportName is ${JSON.stringify(entry.exportName)}, but Mitosis parsed ${JSON.stringify(implementation.name)} from ${entry.source}`);
@@ -1415,7 +3380,7 @@ async function loadCompilerProject(config, projectRoot, projectRootReal) {
1415
3380
  if (!Array.isArray(entry.styles ?? []) || !Array.isArray(entry.assets ?? [])) {
1416
3381
  throw new Error(`${prefix}.styles and ${prefix}.assets must be arrays of project-relative file references`);
1417
3382
  }
1418
- const sourceDirectory = dirname(entry.source).split(sep).join("/");
3383
+ const sourceDirectory = dirname2(entry.source).split(sep2).join("/");
1419
3384
  return {
1420
3385
  manifest,
1421
3386
  implementation: { kind: "mitosis", component: implementation },
@@ -1424,12 +3389,12 @@ async function loadCompilerProject(config, projectRoot, projectRootReal) {
1424
3389
  assets: entry.assets ?? []
1425
3390
  };
1426
3391
  }));
1427
- return { schemaVersion: "1", components };
3392
+ return { schemaVersion: "1", components, styles };
1428
3393
  }
1429
3394
  async function writeArtifact(outputRoot, relativePath, contents) {
1430
- if (!isSafeRelativePath2(relativePath)) throw new Error(`Unsafe generated output path: ${relativePath}`);
3395
+ if (!isSafeRelativePath3(relativePath)) throw new Error(`Unsafe generated output path: ${relativePath}`);
1431
3396
  const parts = relativePath.split("/");
1432
- const directory = parts.slice(0, -1).join(sep);
3397
+ const directory = parts.slice(0, -1).join(sep2);
1433
3398
  const parent = await ensureDirectoryWithoutSymlinks(outputRoot, directory);
1434
3399
  const destination = join(parent, parts.at(-1));
1435
3400
  try {
@@ -1458,15 +3423,16 @@ function printDiagnostics(output, diagnostics) {
1458
3423
  }
1459
3424
  async function runCli(args, output = console, cwd = process.cwd()) {
1460
3425
  try {
3426
+ if (args[0] === "kit") return await runKitCommand(args.slice(1), output, cwd);
1461
3427
  const parsed = parseArguments(args);
1462
3428
  if ("help" in parsed) {
1463
3429
  output.log(HELP);
1464
3430
  return 0;
1465
3431
  }
1466
- const projectRoot = resolve(cwd, parsed.projectRoot ?? ".");
1467
- const projectRootReal = await realpath(projectRoot);
1468
- const configPath = resolve(projectRoot, parsed.config);
1469
- const configText = await readFile(configPath, "utf8");
3432
+ const projectRoot = resolve2(cwd, parsed.projectRoot ?? ".");
3433
+ const projectRootReal = await realpath2(projectRoot);
3434
+ const configPath = resolve2(projectRoot, parsed.config);
3435
+ const configText = await readFile2(configPath, "utf8");
1470
3436
  const projectConfig = JSON.parse(configText);
1471
3437
  const project = await loadCompilerProject(projectConfig, projectRoot, projectRootReal);
1472
3438
  const registry = createMitosisCompiler();
@@ -1521,8 +3487,8 @@ async function runCli(args, output = console, cwd = process.cwd()) {
1521
3487
  for (const [outputPath, sourcePath] of assetSources) {
1522
3488
  let temporary = "";
1523
3489
  try {
1524
- if (!isSafeRelativePath2(outputPath)) throw new Error(`Unsafe asset output path: ${outputPath}`);
1525
- const relativeParent = dirname(outputPath).split(sep).join("/");
3490
+ if (!isSafeRelativePath3(outputPath)) throw new Error(`Unsafe asset output path: ${outputPath}`);
3491
+ const relativeParent = dirname2(outputPath).split(sep2).join("/");
1526
3492
  const parent = await ensureDirectoryWithoutSymlinks(outputRoot, relativeParent === "." ? "" : relativeParent);
1527
3493
  const destination = join(parent, outputPath.split("/").at(-1));
1528
3494
  try {
@@ -1539,7 +3505,7 @@ async function runCli(args, output = console, cwd = process.cwd()) {
1539
3505
  throw cause;
1540
3506
  }
1541
3507
  }
1542
- output.log(`Compiled ${project.components.length} components for ${target}; wrote ${outputFiles.length} generated files and ${result.assets.length} assets to ${relative(projectRoot, outputRoot)}.`);
3508
+ output.log(`Compiled ${project.components.length} components for ${target}; wrote ${outputFiles.length} generated files and ${result.assets.length} assets to ${relative2(projectRoot, outputRoot)}.`);
1543
3509
  return 0;
1544
3510
  } catch (cause) {
1545
3511
  output.error(cause instanceof Error ? cause.message : String(cause));