@foundrykit/cli 2.0.4 → 2.0.6
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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +16 -0
- package/dist/cli.js +176 -66
- package/dist/cli.js.map +1 -1
- package/dist/index.js +176 -66
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/commands/add.ts +280 -123
- package/src/commands/update.ts +1 -1
- package/tests/dependency-resolution.test.ts +127 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
> @foundrykit/cli@
|
|
3
|
+
> @foundrykit/cli@2.0.4 build /Users/isj/Desktop/work/projects/foundry/packages/cli
|
|
4
4
|
> tsup
|
|
5
5
|
|
|
6
6
|
[34mCLI[39m Building entry: {"index":"src/index.ts","cli":"src/index.ts"}
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
[34mCLI[39m Target: es2022
|
|
11
11
|
[34mCLI[39m Cleaning output folder
|
|
12
12
|
[34mESM[39m Build start
|
|
13
|
-
[32mESM[39m [1mdist/cli.js [22m[
|
|
14
|
-
[32mESM[39m [1mdist/
|
|
15
|
-
[32mESM[39m [1mdist/
|
|
16
|
-
[32mESM[39m [1mdist/index.js.map [22m[
|
|
17
|
-
[32mESM[39m ⚡️ Build success in
|
|
13
|
+
[32mESM[39m [1mdist/cli.js [22m[32m66.23 KB[39m
|
|
14
|
+
[32mESM[39m [1mdist/cli.js.map [22m[32m125.18 KB[39m
|
|
15
|
+
[32mESM[39m [1mdist/index.js [22m[32m66.23 KB[39m
|
|
16
|
+
[32mESM[39m [1mdist/index.js.map [22m[32m125.18 KB[39m
|
|
17
|
+
[32mESM[39m ⚡️ Build success in 24ms
|
|
18
18
|
DTS Build start
|
|
19
|
-
DTS ⚡️ Build success in
|
|
19
|
+
DTS ⚡️ Build success in 1028ms
|
|
20
20
|
DTS dist/index.d.ts 20.00 B
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @foundrykit/cli
|
|
2
2
|
|
|
3
|
+
## 2.0.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- updates
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @foundrykit/types@2.0.2
|
|
10
|
+
|
|
11
|
+
## 2.0.5
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- updates and adding in new component
|
|
16
|
+
- Updated dependencies
|
|
17
|
+
- @foundrykit/types@2.0.1
|
|
18
|
+
|
|
3
19
|
## 2.0.4
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/cli.js
CHANGED
|
@@ -1451,72 +1451,187 @@ async function loadConfig() {
|
|
|
1451
1451
|
}
|
|
1452
1452
|
function transformImportsForConfig(content, config) {
|
|
1453
1453
|
let transformed = content;
|
|
1454
|
-
const
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1454
|
+
const importPaths = getConfiguredImportPaths(config);
|
|
1455
|
+
transformed = transformRegistryBarrelImports(
|
|
1456
|
+
transformed,
|
|
1457
|
+
["@foundrykit/primitives", "@/components/primitives", "@/components/ui"],
|
|
1458
|
+
importPaths.primitives,
|
|
1459
|
+
config,
|
|
1460
|
+
"primitives"
|
|
1461
|
+
);
|
|
1462
|
+
transformed = transformRegistryBarrelImports(
|
|
1463
|
+
transformed,
|
|
1464
|
+
["@foundrykit/components", "@/components/components"],
|
|
1465
|
+
importPaths.components,
|
|
1466
|
+
config,
|
|
1467
|
+
"components"
|
|
1468
|
+
);
|
|
1469
|
+
transformed = transformRegistryBarrelImports(
|
|
1470
|
+
transformed,
|
|
1471
|
+
["@foundrykit/blocks", "@/components/blocks"],
|
|
1472
|
+
importPaths.blocks,
|
|
1473
|
+
config,
|
|
1474
|
+
"blocks"
|
|
1475
|
+
);
|
|
1476
|
+
transformed = transformRegistryBarrelImports(
|
|
1477
|
+
transformed,
|
|
1478
|
+
["@foundrykit/animation", "@/components/animations"],
|
|
1479
|
+
importPaths.animations,
|
|
1480
|
+
config,
|
|
1481
|
+
"animations"
|
|
1482
|
+
);
|
|
1483
|
+
transformed = transformed.replace(/@foundrykit\/utils/g, importPaths.utils).replace(/@\/lib\/utils/g, importPaths.utils);
|
|
1484
|
+
return transformed;
|
|
1485
|
+
}
|
|
1486
|
+
function getConfiguredImportPaths(config) {
|
|
1487
|
+
const paths = config?.paths || {
|
|
1461
1488
|
primitives: "components/primitives",
|
|
1462
1489
|
components: "components",
|
|
1463
1490
|
blocks: "components/blocks",
|
|
1464
1491
|
animations: "components/animations",
|
|
1465
1492
|
utils: "lib/utils"
|
|
1466
1493
|
};
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
(
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1494
|
+
return {
|
|
1495
|
+
primitives: resolveImportBasePath(paths.primitives, config),
|
|
1496
|
+
components: resolveImportBasePath(paths.components, config),
|
|
1497
|
+
blocks: resolveImportBasePath(paths.blocks, config),
|
|
1498
|
+
animations: resolveImportBasePath(paths.animations, config),
|
|
1499
|
+
utils: resolveImportBasePath(paths.utils, config).replace(
|
|
1500
|
+
/\.(ts|js)x?$/,
|
|
1501
|
+
""
|
|
1502
|
+
)
|
|
1503
|
+
};
|
|
1504
|
+
}
|
|
1505
|
+
function resolveImportBasePath(filePath, config) {
|
|
1506
|
+
const normalizedPath = normalizeConfigPath(filePath).replace(
|
|
1507
|
+
/\.(ts|js)x?$/,
|
|
1508
|
+
""
|
|
1476
1509
|
);
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1510
|
+
const aliases = config?.aliases ?? {};
|
|
1511
|
+
const aliasMatches = Object.entries(aliases).map(([alias, target]) => ({
|
|
1512
|
+
alias,
|
|
1513
|
+
target: normalizeConfigPath(target)
|
|
1514
|
+
})).filter(({ target }) => {
|
|
1515
|
+
return normalizedPath === target || target !== "" && normalizedPath.startsWith(`${target}/`) || target === "";
|
|
1516
|
+
}).sort((a, b) => b.target.length - a.target.length);
|
|
1517
|
+
const bestMatch = aliasMatches[0];
|
|
1518
|
+
if (bestMatch) {
|
|
1519
|
+
const relativePath = bestMatch.target === "" ? normalizedPath : normalizedPath.slice(bestMatch.target.length).replace(/^\//, "");
|
|
1520
|
+
return joinImportPath(bestMatch.alias, relativePath);
|
|
1521
|
+
}
|
|
1522
|
+
return joinImportPath("@", normalizedPath);
|
|
1523
|
+
}
|
|
1524
|
+
function normalizeConfigPath(filePath) {
|
|
1525
|
+
return filePath.replace(/\\/g, "/").replace(/^\.\//, "").replace(/^\.\/?$/, "").replace(/\/$/, "");
|
|
1526
|
+
}
|
|
1527
|
+
function joinImportPath(basePath, childPath) {
|
|
1528
|
+
const normalizedBase = basePath.replace(/\/$/, "");
|
|
1529
|
+
const normalizedChild = childPath.replace(/^\//, "").replace(/\/$/, "");
|
|
1530
|
+
if (!normalizedChild) {
|
|
1531
|
+
return normalizedBase;
|
|
1532
|
+
}
|
|
1533
|
+
return `${normalizedBase}/${normalizedChild}`;
|
|
1534
|
+
}
|
|
1535
|
+
function transformRegistryBarrelImports(content, sources, destinationBasePath, config, category) {
|
|
1536
|
+
const sourcePattern = sources.map((source) => source.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|");
|
|
1537
|
+
const importPattern = new RegExp(
|
|
1538
|
+
`import\\s+{([^}]+)}\\s+from\\s+["'](${sourcePattern})["'];?`,
|
|
1539
|
+
"g"
|
|
1486
1540
|
);
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
(
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1541
|
+
return content.replace(importPattern, (match, imports) => {
|
|
1542
|
+
const groupedImports = groupImportsByComponent(imports, config, category);
|
|
1543
|
+
return Array.from(groupedImports.entries()).map(([componentPath, specifiers]) => {
|
|
1544
|
+
return `import { ${specifiers.join(", ")} } from "${destinationBasePath}/${componentPath}";`;
|
|
1545
|
+
}).join("\n");
|
|
1546
|
+
});
|
|
1547
|
+
}
|
|
1548
|
+
function groupImportsByComponent(imports, config, category) {
|
|
1549
|
+
const groupedImports = /* @__PURE__ */ new Map();
|
|
1550
|
+
const exportMap = getInstalledComponentExportMap(config, category);
|
|
1551
|
+
const specifiers = imports.split(",").map((specifier) => specifier.trim()).filter(Boolean);
|
|
1552
|
+
const exportNames = specifiers.map(getExportNameFromSpecifier);
|
|
1553
|
+
for (const specifier of specifiers) {
|
|
1554
|
+
const componentPath = getComponentPathForSpecifier(
|
|
1555
|
+
specifier,
|
|
1556
|
+
exportNames,
|
|
1557
|
+
exportMap
|
|
1558
|
+
);
|
|
1559
|
+
const existing = groupedImports.get(componentPath) ?? [];
|
|
1560
|
+
existing.push(specifier);
|
|
1561
|
+
groupedImports.set(componentPath, existing);
|
|
1562
|
+
}
|
|
1563
|
+
return groupedImports;
|
|
1564
|
+
}
|
|
1565
|
+
function getComponentPathForSpecifier(specifier, importExportNames, exportMap) {
|
|
1566
|
+
const exportName = getExportNameFromSpecifier(specifier);
|
|
1567
|
+
const mappedPath = exportMap.get(exportName);
|
|
1568
|
+
if (mappedPath) {
|
|
1569
|
+
return mappedPath;
|
|
1570
|
+
}
|
|
1571
|
+
const siblingOwnerName = importExportNames.filter((name) => name !== exportName).sort((a, b) => a.length - b.length).find((name) => exportName.toLowerCase().startsWith(name.toLowerCase()));
|
|
1572
|
+
if (siblingOwnerName) {
|
|
1573
|
+
return exportMap.get(siblingOwnerName) ?? toKebabCase(siblingOwnerName);
|
|
1574
|
+
}
|
|
1575
|
+
const variantsOwnerName = exportName.replace(/Variants$/, "");
|
|
1576
|
+
if (variantsOwnerName !== exportName) {
|
|
1577
|
+
return exportMap.get(variantsOwnerName) ?? toKebabCase(variantsOwnerName);
|
|
1578
|
+
}
|
|
1579
|
+
return toKebabCase(exportName);
|
|
1580
|
+
}
|
|
1581
|
+
function getExportNameFromSpecifier(specifier) {
|
|
1582
|
+
return specifier.replace(/^type\s+/, "").split(/\s+as\s+/)[0]?.trim() || specifier;
|
|
1583
|
+
}
|
|
1584
|
+
function getInstalledComponentExportMap(config, category) {
|
|
1585
|
+
const exportMap = /* @__PURE__ */ new Map();
|
|
1586
|
+
const categoryPath = config.paths?.[category];
|
|
1587
|
+
if (!categoryPath) {
|
|
1588
|
+
return exportMap;
|
|
1589
|
+
}
|
|
1590
|
+
const absoluteCategoryPath = path3.resolve(
|
|
1591
|
+
process.cwd(),
|
|
1592
|
+
normalizeConfigPath(categoryPath)
|
|
1496
1593
|
);
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1594
|
+
if (!fs3.existsSync(absoluteCategoryPath)) {
|
|
1595
|
+
return exportMap;
|
|
1596
|
+
}
|
|
1597
|
+
for (const entry of fs3.readdirSync(absoluteCategoryPath, {
|
|
1598
|
+
withFileTypes: true
|
|
1599
|
+
})) {
|
|
1600
|
+
if (!entry.isDirectory()) continue;
|
|
1601
|
+
const componentPath = entry.name;
|
|
1602
|
+
const componentDir = path3.join(absoluteCategoryPath, componentPath);
|
|
1603
|
+
const entryFiles = ["index.tsx", "index.ts", "index.jsx", "index.js"].map((fileName) => path3.join(componentDir, fileName)).filter((filePath) => fs3.existsSync(filePath));
|
|
1604
|
+
for (const filePath of entryFiles) {
|
|
1605
|
+
const content = fs3.readFileSync(filePath, "utf-8");
|
|
1606
|
+
for (const exportName of parseExportNames(content)) {
|
|
1607
|
+
exportMap.set(exportName, componentPath);
|
|
1608
|
+
}
|
|
1505
1609
|
}
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1610
|
+
}
|
|
1611
|
+
return exportMap;
|
|
1612
|
+
}
|
|
1613
|
+
function parseExportNames(content) {
|
|
1614
|
+
const exportNames = /* @__PURE__ */ new Set();
|
|
1615
|
+
const namedExportPattern = /export\s*{\s*([^}]+)\s*}/g;
|
|
1616
|
+
const declarationExportPattern = /export\s+(?:declare\s+)?(?:const|let|var|function|class|interface|type|enum)\s+([A-Za-z_$][\w$]*)/g;
|
|
1617
|
+
for (const match of content.matchAll(namedExportPattern)) {
|
|
1618
|
+
const exports = match[1] ?? "";
|
|
1619
|
+
for (const rawExport of exports.split(",")) {
|
|
1620
|
+
const exportName = rawExport.trim().replace(/^type\s+/, "").split(/\s+as\s+/).pop()?.trim();
|
|
1621
|
+
if (exportName) {
|
|
1622
|
+
exportNames.add(exportName);
|
|
1623
|
+
}
|
|
1515
1624
|
}
|
|
1516
|
-
|
|
1517
|
-
const
|
|
1518
|
-
|
|
1519
|
-
|
|
1625
|
+
}
|
|
1626
|
+
for (const match of content.matchAll(declarationExportPattern)) {
|
|
1627
|
+
if (match[1]) {
|
|
1628
|
+
exportNames.add(match[1]);
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
return Array.from(exportNames);
|
|
1632
|
+
}
|
|
1633
|
+
function toKebabCase(value) {
|
|
1634
|
+
return value.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1-$2").toLowerCase();
|
|
1520
1635
|
}
|
|
1521
1636
|
function resolveComponentPath(originalPath, category, config) {
|
|
1522
1637
|
const paths = config?.paths || {
|
|
@@ -1560,21 +1675,16 @@ function getImportPath(componentData, config) {
|
|
|
1560
1675
|
utils: "lib/utils"
|
|
1561
1676
|
};
|
|
1562
1677
|
const componentName = path3.basename(
|
|
1563
|
-
componentData.files[0]?.path || ""
|
|
1564
|
-
".tsx"
|
|
1678
|
+
path3.dirname(componentData.files[0]?.path || "")
|
|
1565
1679
|
);
|
|
1566
1680
|
if (componentData.category === "primitives") {
|
|
1567
|
-
|
|
1568
|
-
return `@/${primitivesPath}/${componentName}`;
|
|
1681
|
+
return `${resolveImportBasePath(paths.primitives, config)}/${componentName}`;
|
|
1569
1682
|
} else if (componentData.category === "components") {
|
|
1570
|
-
|
|
1571
|
-
return `@/${componentsPath}/${componentName}`;
|
|
1683
|
+
return `${resolveImportBasePath(paths.components, config)}/${componentName}`;
|
|
1572
1684
|
} else if (componentData.category === "blocks") {
|
|
1573
|
-
|
|
1574
|
-
return `@/${blocksPath}/${componentName}`;
|
|
1685
|
+
return `${resolveImportBasePath(paths.blocks, config)}/${componentName}`;
|
|
1575
1686
|
} else if (componentData.category === "animations") {
|
|
1576
|
-
|
|
1577
|
-
return `@/${animationsPath}/${componentName}`;
|
|
1687
|
+
return `${resolveImportBasePath(paths.animations, config)}/${componentName}`;
|
|
1578
1688
|
}
|
|
1579
1689
|
return `@/components/${componentName}`;
|
|
1580
1690
|
}
|
|
@@ -1675,7 +1785,7 @@ function updateCommand() {
|
|
|
1675
1785
|
const upToDate = [];
|
|
1676
1786
|
for (const compId of installedIds) {
|
|
1677
1787
|
try {
|
|
1678
|
-
const data = await registry.getComponent(compId);
|
|
1788
|
+
const data = await registry.getComponent(compId, options.force);
|
|
1679
1789
|
const installedVersion = installed[compId]?.version ?? null;
|
|
1680
1790
|
const latestVersion = data.version ?? null;
|
|
1681
1791
|
const hasUpdate = latestVersion !== null && installedVersion !== null && latestVersion !== installedVersion;
|