@foundrykit/cli 2.0.11 → 2.0.12
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-type-check.log +1 -1
- package/CHANGELOG.md +9 -0
- package/README.md +37 -35
- package/dist/cli.js +1896 -1894
- package/dist/cli.js.map +1 -1
- package/dist/index.js +1896 -1894
- package/dist/index.js.map +1 -1
- package/package.json +8 -6
- package/postcss.config.mjs +1 -1
- package/src/commands/add.ts +22 -18
- package/src/commands/doctor.ts +10 -7
- package/src/commands/init.ts +13 -20
- package/src/commands/list.ts +3 -6
- package/src/commands/update.ts +8 -8
- package/src/index.ts +5 -5
- package/src/lib/registry.ts +36 -33
- package/tests/dependency-resolution.test.ts +31 -22
- package/.turbo/turbo-build.log +0 -19
- package/.turbo/turbo-test.log +0 -42
- package/eslint.config.js +0 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@foundrykit/cli",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.12",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -25,23 +25,25 @@
|
|
|
25
25
|
"glob": "^10.3.10",
|
|
26
26
|
"inquirer": "^9.2.15",
|
|
27
27
|
"node-fetch": "^3.3.0",
|
|
28
|
-
"@foundrykit/types": "2.0.
|
|
28
|
+
"@foundrykit/types": "2.0.7"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/node": "^20.19.9",
|
|
32
32
|
"@types/fs-extra": "^11.0.4",
|
|
33
33
|
"@types/inquirer": "^9.0.7",
|
|
34
|
-
"eslint": "^9.0.0",
|
|
35
34
|
"tsup": "^8.0.0",
|
|
36
35
|
"typescript": "^5.9.2",
|
|
37
36
|
"vitest": "^1.2.0",
|
|
38
|
-
"@foundrykit/
|
|
39
|
-
|
|
37
|
+
"@foundrykit/typescript-config": "1.0.6"
|
|
38
|
+
},
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "git+https://github.com/umi-labs/foundry.git",
|
|
42
|
+
"directory": "packages/cli"
|
|
40
43
|
},
|
|
41
44
|
"scripts": {
|
|
42
45
|
"build": "tsup",
|
|
43
46
|
"dev": "tsup --watch",
|
|
44
|
-
"lint": "eslint . --max-warnings 0",
|
|
45
47
|
"type-check": "tsc --noEmit",
|
|
46
48
|
"test": "vitest run",
|
|
47
49
|
"test:watch": "vitest --watch"
|
package/postcss.config.mjs
CHANGED
package/src/commands/add.ts
CHANGED
|
@@ -3,21 +3,21 @@
|
|
|
3
3
|
* Handles adding components to projects
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import path from 'path';
|
|
10
|
-
import inquirer from 'inquirer';
|
|
11
|
-
import { exec } from 'child_process';
|
|
12
|
-
import { promisify } from 'util';
|
|
6
|
+
import { exec } from 'node:child_process';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { promisify } from 'node:util';
|
|
13
9
|
import type {
|
|
14
|
-
ComponentMeta,
|
|
15
|
-
ComponentData,
|
|
16
10
|
ComponentCategory,
|
|
11
|
+
ComponentData,
|
|
12
|
+
ComponentMeta,
|
|
17
13
|
Config,
|
|
18
14
|
} from '@foundrykit/types';
|
|
19
|
-
import
|
|
15
|
+
import chalk from 'chalk';
|
|
16
|
+
import { Command } from 'commander';
|
|
17
|
+
import fs from 'fs-extra';
|
|
18
|
+
import inquirer from 'inquirer';
|
|
20
19
|
import { CLI_VERSION, REGISTRY_CATEGORY_ORDER } from '../lib/constants.js';
|
|
20
|
+
import { getRegistry } from '../lib/registry.js';
|
|
21
21
|
|
|
22
22
|
const execAsync = promisify(exec);
|
|
23
23
|
|
|
@@ -125,7 +125,12 @@ function createGroupedChoices(components: ComponentMeta[]) {
|
|
|
125
125
|
.filter(category => !knownCategories.has(category)),
|
|
126
126
|
];
|
|
127
127
|
|
|
128
|
-
const choices:
|
|
128
|
+
const choices: Array<{
|
|
129
|
+
name: string;
|
|
130
|
+
value: string;
|
|
131
|
+
short?: string;
|
|
132
|
+
disabled?: boolean;
|
|
133
|
+
}> = [];
|
|
129
134
|
|
|
130
135
|
for (const category of categories) {
|
|
131
136
|
const categoryComponents = components.filter(c => c.category === category);
|
|
@@ -396,7 +401,8 @@ export async function handlePackageDependencies(
|
|
|
396
401
|
const allDependencies = new Set<string>();
|
|
397
402
|
|
|
398
403
|
if (componentData.packageDependencies?.length) {
|
|
399
|
-
|
|
404
|
+
for (const dep of componentData.packageDependencies)
|
|
405
|
+
allDependencies.add(dep);
|
|
400
406
|
}
|
|
401
407
|
|
|
402
408
|
if (allDependencies.size === 0) {
|
|
@@ -416,9 +422,7 @@ export async function handlePackageDependencies(
|
|
|
416
422
|
}
|
|
417
423
|
|
|
418
424
|
const packagesToInstall = missingPackages.map(pkg =>
|
|
419
|
-
forcePackageUpdate
|
|
420
|
-
? getPackageInstallSpec(pkg, componentData.version)
|
|
421
|
-
: pkg
|
|
425
|
+
forcePackageUpdate ? getPackageInstallSpec(pkg, componentData.version) : pkg
|
|
422
426
|
);
|
|
423
427
|
|
|
424
428
|
console.log(
|
|
@@ -437,14 +441,14 @@ export async function handlePackageDependencies(
|
|
|
437
441
|
const installCommand = `${packageManager} add ${packagesToInstall.join(' ')}`;
|
|
438
442
|
console.log(chalk.blue(` Running: ${installCommand}`));
|
|
439
443
|
|
|
440
|
-
const {
|
|
444
|
+
const { stderr } = await execAsync(installCommand);
|
|
441
445
|
|
|
442
446
|
if (stderr && !stderr.includes('warning')) {
|
|
443
447
|
console.error(chalk.yellow(` Warning: ${stderr}`));
|
|
444
448
|
}
|
|
445
449
|
|
|
446
450
|
console.log(chalk.green('✅ Packages installed successfully'));
|
|
447
|
-
} catch
|
|
451
|
+
} catch {
|
|
448
452
|
console.log(chalk.yellow('\n⚠️ Could not install packages automatically'));
|
|
449
453
|
console.log(chalk.gray(' Please install them manually:'));
|
|
450
454
|
console.log(
|
|
@@ -477,7 +481,7 @@ export async function getMissingPackages(
|
|
|
477
481
|
};
|
|
478
482
|
|
|
479
483
|
return packages.filter(pkg => !installedPackages[pkg]);
|
|
480
|
-
} catch
|
|
484
|
+
} catch {
|
|
481
485
|
// If we can't read package.json, assume all packages are missing
|
|
482
486
|
return packages;
|
|
483
487
|
}
|
package/src/commands/doctor.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import path from 'node:path';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
|
+
import { Command } from 'commander';
|
|
3
4
|
import fs from 'fs-extra';
|
|
4
|
-
import path from 'path';
|
|
5
5
|
import { DEFAULT_REGISTRY_URL } from '../lib/constants.js';
|
|
6
6
|
import { loadConfig } from './add.js';
|
|
7
7
|
|
|
@@ -29,7 +29,10 @@ export function doctorCommand() {
|
|
|
29
29
|
: 'Run this command in a project root',
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
-
let packageJson:
|
|
32
|
+
let packageJson: {
|
|
33
|
+
dependencies?: Record<string, string>;
|
|
34
|
+
devDependencies?: Record<string, string>;
|
|
35
|
+
} | null = null;
|
|
33
36
|
if (hasPackageJson) {
|
|
34
37
|
packageJson = await fs.readJson(packageJsonPath);
|
|
35
38
|
}
|
|
@@ -55,9 +58,7 @@ export function doctorCommand() {
|
|
|
55
58
|
: 'Run "foundrykit init" to create the configuration file',
|
|
56
59
|
});
|
|
57
60
|
|
|
58
|
-
let config:
|
|
59
|
-
| Awaited<ReturnType<typeof loadConfig>>
|
|
60
|
-
| null = null;
|
|
61
|
+
let config: Awaited<ReturnType<typeof loadConfig>> | null = null;
|
|
61
62
|
if (hasConfig) {
|
|
62
63
|
try {
|
|
63
64
|
config = await loadConfig();
|
|
@@ -117,7 +118,9 @@ export function doctorCommand() {
|
|
|
117
118
|
const hasFailures = results.some(result => !result.ok);
|
|
118
119
|
if (hasFailures) {
|
|
119
120
|
console.log(
|
|
120
|
-
chalk.yellow(
|
|
121
|
+
chalk.yellow(
|
|
122
|
+
'\n⚠️ Found issues that should be resolved before continuing.'
|
|
123
|
+
)
|
|
121
124
|
);
|
|
122
125
|
process.exit(1);
|
|
123
126
|
}
|
package/src/commands/init.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { exec } from 'node:child_process';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { promisify } from 'node:util';
|
|
2
4
|
import chalk from 'chalk';
|
|
5
|
+
import { Command } from 'commander';
|
|
3
6
|
import fs from 'fs-extra';
|
|
4
|
-
import path from 'path';
|
|
5
7
|
import inquirer from 'inquirer';
|
|
6
|
-
import { exec } from 'child_process';
|
|
7
|
-
import { promisify } from 'util';
|
|
8
8
|
import { CLI_VERSION, DEFAULT_REGISTRY_URL } from '../lib/constants.js';
|
|
9
9
|
|
|
10
10
|
interface InitOptions {
|
|
@@ -266,7 +266,6 @@ async function getPathConfiguration(
|
|
|
266
266
|
skipPrompts?: boolean
|
|
267
267
|
): Promise<PathConfig> {
|
|
268
268
|
const ext = structure.isTypeScript ? '.ts' : '.js';
|
|
269
|
-
const jsxExt = structure.isTypeScript ? '.tsx' : '.jsx';
|
|
270
269
|
|
|
271
270
|
// Smart defaults based on existing structure
|
|
272
271
|
const defaults: PathConfig = {
|
|
@@ -434,7 +433,7 @@ async function installDependencies(): Promise<void> {
|
|
|
434
433
|
);
|
|
435
434
|
|
|
436
435
|
console.log(chalk.green('✅ Dependencies installed'));
|
|
437
|
-
} catch
|
|
436
|
+
} catch {
|
|
438
437
|
console.error(chalk.yellow('⚠️ Failed to install some dependencies'));
|
|
439
438
|
console.error(chalk.gray('You may need to install them manually'));
|
|
440
439
|
}
|
|
@@ -501,7 +500,7 @@ async function setupTailwindV4(
|
|
|
501
500
|
}
|
|
502
501
|
|
|
503
502
|
// User wants to switch to local globals.css
|
|
504
|
-
await createOrUpdateGlobalsCss(pathConfig
|
|
503
|
+
await createOrUpdateGlobalsCss(pathConfig);
|
|
505
504
|
await updateLayoutImport(layoutPath, pathConfig);
|
|
506
505
|
return;
|
|
507
506
|
}
|
|
@@ -511,7 +510,7 @@ async function setupTailwindV4(
|
|
|
511
510
|
/import\s+['"]([^'"]*globals?\.css)['"]/
|
|
512
511
|
);
|
|
513
512
|
|
|
514
|
-
if (globalsCssImportMatch
|
|
513
|
+
if (globalsCssImportMatch?.[1]) {
|
|
515
514
|
// Local globals.css is imported, update it
|
|
516
515
|
const importPath = globalsCssImportMatch[1];
|
|
517
516
|
const resolvedPath = resolveImportPath(layoutPath, importPath);
|
|
@@ -552,9 +551,9 @@ async function setupTailwindV4(
|
|
|
552
551
|
}
|
|
553
552
|
|
|
554
553
|
if (setupPreference === 'direct') {
|
|
555
|
-
await addDirectImportToLayout(layoutPath
|
|
554
|
+
await addDirectImportToLayout(layoutPath!);
|
|
556
555
|
} else {
|
|
557
|
-
await createOrUpdateGlobalsCss(pathConfig
|
|
556
|
+
await createOrUpdateGlobalsCss(pathConfig);
|
|
558
557
|
if (layoutPath) {
|
|
559
558
|
await updateLayoutImport(layoutPath, pathConfig);
|
|
560
559
|
}
|
|
@@ -563,10 +562,7 @@ async function setupTailwindV4(
|
|
|
563
562
|
console.log(chalk.green('✅ Tailwind CSS v4 configured'));
|
|
564
563
|
}
|
|
565
564
|
|
|
566
|
-
async function createOrUpdateGlobalsCss(
|
|
567
|
-
pathConfig: PathConfig,
|
|
568
|
-
projectStructure: ProjectStructure
|
|
569
|
-
): Promise<void> {
|
|
565
|
+
async function createOrUpdateGlobalsCss(pathConfig: PathConfig): Promise<void> {
|
|
570
566
|
const globalsCssPath = path.join(process.cwd(), pathConfig.styles);
|
|
571
567
|
|
|
572
568
|
// Check if file already exists
|
|
@@ -696,15 +692,12 @@ async function updateLayoutImport(
|
|
|
696
692
|
`Updated ${path.relative(process.cwd(), layoutPath)} with CSS import`
|
|
697
693
|
)
|
|
698
694
|
);
|
|
699
|
-
} catch
|
|
695
|
+
} catch {
|
|
700
696
|
console.error(chalk.yellow('⚠️ Failed to update layout with CSS import'));
|
|
701
697
|
}
|
|
702
698
|
}
|
|
703
699
|
|
|
704
|
-
async function addDirectImportToLayout(
|
|
705
|
-
layoutPath: string,
|
|
706
|
-
pathConfig: PathConfig
|
|
707
|
-
): Promise<void> {
|
|
700
|
+
async function addDirectImportToLayout(layoutPath: string): Promise<void> {
|
|
708
701
|
try {
|
|
709
702
|
let content = await fs.readFile(layoutPath, 'utf-8');
|
|
710
703
|
const importStatement = `import '@foundrykit/tailwind/globals.css';\n`;
|
|
@@ -731,7 +724,7 @@ async function addDirectImportToLayout(
|
|
|
731
724
|
chalk.green('✅ Added direct import of FoundryKit styles to layout')
|
|
732
725
|
);
|
|
733
726
|
}
|
|
734
|
-
} catch
|
|
727
|
+
} catch {
|
|
735
728
|
console.error(chalk.yellow('⚠️ Failed to add CSS import to layout'));
|
|
736
729
|
}
|
|
737
730
|
}
|
package/src/commands/list.ts
CHANGED
|
@@ -3,14 +3,11 @@
|
|
|
3
3
|
* Displays available components from the registry
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import type { ComponentCategory, ComponentMeta } from '@foundrykit/types';
|
|
7
7
|
import chalk from 'chalk';
|
|
8
|
-
import
|
|
9
|
-
import fs from 'fs-extra';
|
|
10
|
-
import path from 'path';
|
|
11
|
-
import type { ComponentMeta, ComponentCategory } from '@foundrykit/types';
|
|
12
|
-
import { getRegistry } from '../lib/registry.js';
|
|
8
|
+
import { Command } from 'commander';
|
|
13
9
|
import { REGISTRY_CATEGORY_ORDER } from '../lib/constants.js';
|
|
10
|
+
import { getRegistry } from '../lib/registry.js';
|
|
14
11
|
|
|
15
12
|
interface ListOptions {
|
|
16
13
|
category?: string;
|
package/src/commands/update.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import type { InstalledComponent } from '@foundrykit/types';
|
|
2
3
|
import chalk from 'chalk';
|
|
3
|
-
import
|
|
4
|
+
import { Command } from 'commander';
|
|
4
5
|
import fs from 'fs-extra';
|
|
5
|
-
import
|
|
6
|
+
import inquirer from 'inquirer';
|
|
7
|
+
import { getRegistry } from '../lib/registry.js';
|
|
6
8
|
import {
|
|
9
|
+
type AddOptions,
|
|
7
10
|
addSingleComponent,
|
|
8
11
|
hasConflictingFiles,
|
|
9
|
-
type AddOptions,
|
|
10
12
|
} from './add.js';
|
|
11
|
-
import { getRegistry } from '../lib/registry.js';
|
|
12
|
-
import type { InstalledComponent } from '@foundrykit/types';
|
|
13
13
|
|
|
14
14
|
interface UpdateOptions extends AddOptions {
|
|
15
15
|
opt?: boolean;
|
|
@@ -57,7 +57,7 @@ export function updateCommand() {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
const config = await fs.readJson(configPath);
|
|
60
|
-
|
|
60
|
+
const installed: Record<string, InstalledComponent> =
|
|
61
61
|
config.installedComponents ?? {};
|
|
62
62
|
const installedFoundryKitPackages =
|
|
63
63
|
await getInstalledFoundryKitPackageVersions();
|
|
@@ -83,7 +83,7 @@ export function updateCommand() {
|
|
|
83
83
|
)
|
|
84
84
|
);
|
|
85
85
|
const registry = getRegistry();
|
|
86
|
-
let allComponents
|
|
86
|
+
let allComponents: Awaited<ReturnType<typeof registry.getComponents>>;
|
|
87
87
|
try {
|
|
88
88
|
allComponents = await registry.getComponents();
|
|
89
89
|
} catch (error) {
|
package/src/index.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
3
6
|
import { Command } from 'commander';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { dirname, join } from 'path';
|
|
7
|
+
import { addCommand } from './commands/add.js';
|
|
8
|
+
import { doctorCommand } from './commands/doctor.js';
|
|
7
9
|
import { initCommand } from './commands/init.js';
|
|
8
10
|
import { listCommand } from './commands/list.js';
|
|
9
|
-
import { addCommand } from './commands/add.js';
|
|
10
11
|
import { updateCommand } from './commands/update.js';
|
|
11
|
-
import { doctorCommand } from './commands/doctor.js';
|
|
12
12
|
|
|
13
13
|
// Get package.json version
|
|
14
14
|
const __filename = fileURLToPath(import.meta.url);
|
package/src/lib/registry.ts
CHANGED
|
@@ -3,25 +3,25 @@
|
|
|
3
3
|
* Handles communication with the FoundryKit registry
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import
|
|
7
|
-
import path from 'path';
|
|
8
|
-
import
|
|
6
|
+
import os from 'node:os';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import type {
|
|
9
|
+
CLIConfig,
|
|
10
|
+
ComponentData,
|
|
11
|
+
ComponentMeta,
|
|
12
|
+
LocalCache,
|
|
13
|
+
RegistryComponent,
|
|
14
|
+
RegistryIndex,
|
|
15
|
+
} from '@foundrykit/types';
|
|
9
16
|
import chalk from 'chalk';
|
|
17
|
+
import fs from 'fs-extra';
|
|
10
18
|
import {
|
|
11
|
-
DEFAULT_REGISTRY_URL,
|
|
12
19
|
CACHE_DIR,
|
|
13
20
|
CACHE_TTL,
|
|
21
|
+
DEFAULT_REGISTRY_URL,
|
|
14
22
|
FOUNDRYKIT_PACKAGE_ALIASES,
|
|
15
23
|
NPM_REGISTRY_URL,
|
|
16
24
|
} from './constants.js';
|
|
17
|
-
import type {
|
|
18
|
-
ComponentMeta,
|
|
19
|
-
ComponentData,
|
|
20
|
-
RegistryIndex,
|
|
21
|
-
RegistryComponent,
|
|
22
|
-
LocalCache,
|
|
23
|
-
CLIConfig,
|
|
24
|
-
} from '@foundrykit/types';
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Default configuration
|
|
@@ -59,7 +59,7 @@ export class RegistryService {
|
|
|
59
59
|
if (search) params.append('search', search);
|
|
60
60
|
|
|
61
61
|
const url = `${this.config.registryUrl}/registry${
|
|
62
|
-
params.toString() ?
|
|
62
|
+
params.toString() ? `?${params.toString()}` : ''
|
|
63
63
|
}`;
|
|
64
64
|
|
|
65
65
|
console.log(chalk.gray(`Fetching from: ${url}`));
|
|
@@ -269,7 +269,7 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
269
269
|
};
|
|
270
270
|
|
|
271
271
|
return packageName in allDeps;
|
|
272
|
-
} catch
|
|
272
|
+
} catch {
|
|
273
273
|
return false;
|
|
274
274
|
}
|
|
275
275
|
}
|
|
@@ -279,9 +279,7 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
279
279
|
return id;
|
|
280
280
|
}
|
|
281
281
|
|
|
282
|
-
if (
|
|
283
|
-
/^[a-z0-9][a-z0-9-]*$/i.test(id)
|
|
284
|
-
) {
|
|
282
|
+
if (/^[a-z0-9][a-z0-9-]*$/i.test(id)) {
|
|
285
283
|
return `@foundrykit/${id}`;
|
|
286
284
|
}
|
|
287
285
|
|
|
@@ -369,11 +367,13 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
369
367
|
.filter((pkg): pkg is NonNullable<typeof pkg> => {
|
|
370
368
|
return Boolean(pkg?.name?.startsWith('@foundrykit/'));
|
|
371
369
|
})
|
|
372
|
-
.map(pkg =>
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
370
|
+
.map(pkg =>
|
|
371
|
+
this.toPackageComponentMeta(pkg.name!, {
|
|
372
|
+
version: pkg.version,
|
|
373
|
+
description: pkg.description,
|
|
374
|
+
keywords: pkg.keywords,
|
|
375
|
+
})
|
|
376
|
+
)
|
|
377
377
|
.sort((a, b) => a.id.localeCompare(b.id));
|
|
378
378
|
}
|
|
379
379
|
|
|
@@ -400,7 +400,9 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
400
400
|
return {
|
|
401
401
|
version:
|
|
402
402
|
data['dist-tags']?.latest ??
|
|
403
|
-
Object.keys(data.versions ?? {})
|
|
403
|
+
Object.keys(data.versions ?? {})
|
|
404
|
+
.sort(compareVersions)
|
|
405
|
+
.at(-1),
|
|
404
406
|
description: data.description,
|
|
405
407
|
keywords: data.keywords,
|
|
406
408
|
};
|
|
@@ -428,8 +430,7 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
428
430
|
id,
|
|
429
431
|
name: this.toDisplayName(id),
|
|
430
432
|
version: metadata.version,
|
|
431
|
-
category:
|
|
432
|
-
id === 'maps' ? 'maps' : id === 'hooks' ? 'hooks' : 'packages',
|
|
433
|
+
category: id === 'maps' ? 'maps' : id === 'hooks' ? 'hooks' : 'packages',
|
|
433
434
|
description: metadata.description ?? `${packageName} npm package`,
|
|
434
435
|
tags: metadata.keywords,
|
|
435
436
|
packageDependencies: [packageName],
|
|
@@ -451,7 +452,7 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
451
452
|
|
|
452
453
|
await fs.ensureDir(this.config.cacheDir);
|
|
453
454
|
await fs.writeJson(this.cacheFile, newCache, { spaces: 2 });
|
|
454
|
-
} catch
|
|
455
|
+
} catch {
|
|
455
456
|
// Cache update failed, but don't throw - this is not critical
|
|
456
457
|
console.log(chalk.gray('Failed to update cache'));
|
|
457
458
|
}
|
|
@@ -474,7 +475,7 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
474
475
|
|
|
475
476
|
await fs.ensureDir(this.config.cacheDir);
|
|
476
477
|
await fs.writeJson(this.cacheFile, cache, { spaces: 2 });
|
|
477
|
-
} catch
|
|
478
|
+
} catch {
|
|
478
479
|
// Cache update failed, but don't throw
|
|
479
480
|
console.log(chalk.gray('Failed to cache component'));
|
|
480
481
|
}
|
|
@@ -488,7 +489,7 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
488
489
|
if (await fs.pathExists(this.cacheFile)) {
|
|
489
490
|
return await fs.readJson(this.cacheFile);
|
|
490
491
|
}
|
|
491
|
-
} catch
|
|
492
|
+
} catch {
|
|
492
493
|
console.log(chalk.gray('Failed to load cache'));
|
|
493
494
|
}
|
|
494
495
|
return null;
|
|
@@ -568,7 +569,7 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
568
569
|
componentCount: cache?.components.length || 0,
|
|
569
570
|
};
|
|
570
571
|
}
|
|
571
|
-
} catch
|
|
572
|
+
} catch {
|
|
572
573
|
// Ignore errors
|
|
573
574
|
}
|
|
574
575
|
|
|
@@ -617,8 +618,10 @@ function compareVersions(a: string, b: string): number {
|
|
|
617
618
|
}
|
|
618
619
|
|
|
619
620
|
function normalizeVersion(version: string): string {
|
|
620
|
-
return
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
621
|
+
return (
|
|
622
|
+
version
|
|
623
|
+
.replace(/^[^\d]*/, '')
|
|
624
|
+
.split('-')[0]
|
|
625
|
+
?.replace(/[^\d.]/g, '') || '0'
|
|
626
|
+
);
|
|
624
627
|
}
|
|
@@ -2,16 +2,24 @@
|
|
|
2
2
|
* Tests for dependency resolution in the CLI
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import os from 'node:os';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import type { ComponentData } from '@foundrykit/types';
|
|
6
8
|
import fs from 'fs-extra';
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
import {
|
|
10
|
+
afterEach,
|
|
11
|
+
beforeEach,
|
|
12
|
+
describe,
|
|
13
|
+
expect,
|
|
14
|
+
it,
|
|
15
|
+
type Mock,
|
|
16
|
+
vi,
|
|
17
|
+
} from 'vitest';
|
|
10
18
|
import {
|
|
11
19
|
getImportPath,
|
|
12
20
|
transformImportsForConfig,
|
|
13
21
|
} from '../src/commands/add.js';
|
|
14
|
-
import
|
|
22
|
+
import { RegistryService } from '../src/lib/registry.js';
|
|
15
23
|
|
|
16
24
|
describe('Dependency Resolution', () => {
|
|
17
25
|
let testDir: string;
|
|
@@ -19,7 +27,7 @@ describe('Dependency Resolution', () => {
|
|
|
19
27
|
|
|
20
28
|
beforeEach(async () => {
|
|
21
29
|
// Create a temporary test directory
|
|
22
|
-
testDir = path.join(os.tmpdir(),
|
|
30
|
+
testDir = path.join(os.tmpdir(), `foundrykit-test-${Date.now()}`);
|
|
23
31
|
await fs.ensureDir(testDir);
|
|
24
32
|
|
|
25
33
|
// Create a registry instance with test config
|
|
@@ -81,7 +89,7 @@ describe('Dependency Resolution', () => {
|
|
|
81
89
|
|
|
82
90
|
describe('Registry Component Fetching', () => {
|
|
83
91
|
it('should merge scoped npm packages into the component list', async () => {
|
|
84
|
-
(global.fetch as
|
|
92
|
+
(global.fetch as unknown as Mock)
|
|
85
93
|
.mockResolvedValueOnce({
|
|
86
94
|
ok: true,
|
|
87
95
|
json: async () => [
|
|
@@ -124,7 +132,7 @@ describe('Dependency Resolution', () => {
|
|
|
124
132
|
});
|
|
125
133
|
|
|
126
134
|
it('should resolve explicit scoped npm packages when absent from the registry', async () => {
|
|
127
|
-
(global.fetch as
|
|
135
|
+
(global.fetch as unknown as Mock)
|
|
128
136
|
.mockResolvedValueOnce({
|
|
129
137
|
ok: false,
|
|
130
138
|
status: 404,
|
|
@@ -155,7 +163,7 @@ describe('Dependency Resolution', () => {
|
|
|
155
163
|
});
|
|
156
164
|
|
|
157
165
|
it('should resolve bare npm package IDs surfaced by the package list', async () => {
|
|
158
|
-
(global.fetch as
|
|
166
|
+
(global.fetch as unknown as Mock)
|
|
159
167
|
.mockResolvedValueOnce({
|
|
160
168
|
ok: false,
|
|
161
169
|
status: 404,
|
|
@@ -197,7 +205,7 @@ describe('Dependency Resolution', () => {
|
|
|
197
205
|
],
|
|
198
206
|
};
|
|
199
207
|
|
|
200
|
-
(global.fetch as
|
|
208
|
+
(global.fetch as unknown as Mock).mockResolvedValueOnce({
|
|
201
209
|
ok: true,
|
|
202
210
|
json: async () => mockComponent,
|
|
203
211
|
});
|
|
@@ -211,7 +219,7 @@ describe('Dependency Resolution', () => {
|
|
|
211
219
|
});
|
|
212
220
|
|
|
213
221
|
it('should handle 404 errors for non-existent components', async () => {
|
|
214
|
-
(global.fetch as
|
|
222
|
+
(global.fetch as unknown as Mock).mockResolvedValueOnce({
|
|
215
223
|
ok: false,
|
|
216
224
|
status: 404,
|
|
217
225
|
statusText: 'Not Found',
|
|
@@ -223,7 +231,9 @@ describe('Dependency Resolution', () => {
|
|
|
223
231
|
});
|
|
224
232
|
|
|
225
233
|
it('should handle network errors gracefully', async () => {
|
|
226
|
-
(global.fetch as
|
|
234
|
+
(global.fetch as unknown as Mock).mockRejectedValueOnce(
|
|
235
|
+
new Error('Network error')
|
|
236
|
+
);
|
|
227
237
|
|
|
228
238
|
await expect(registry.getComponent('button')).rejects.toThrow(
|
|
229
239
|
'Failed to fetch component "button"'
|
|
@@ -247,7 +257,7 @@ describe('Dependency Resolution', () => {
|
|
|
247
257
|
],
|
|
248
258
|
};
|
|
249
259
|
|
|
250
|
-
(global.fetch as
|
|
260
|
+
(global.fetch as unknown as Mock).mockResolvedValueOnce({
|
|
251
261
|
ok: true,
|
|
252
262
|
json: async () => mockComponent,
|
|
253
263
|
});
|
|
@@ -257,7 +267,9 @@ describe('Dependency Resolution', () => {
|
|
|
257
267
|
expect(global.fetch).toHaveBeenCalledTimes(1);
|
|
258
268
|
|
|
259
269
|
// Second fetch - should use cache
|
|
260
|
-
(global.fetch as
|
|
270
|
+
(global.fetch as unknown as Mock).mockRejectedValueOnce(
|
|
271
|
+
new Error('Network error')
|
|
272
|
+
);
|
|
261
273
|
const cached = await registry.getComponent('card');
|
|
262
274
|
|
|
263
275
|
expect(cached).toEqual(mockComponent);
|
|
@@ -333,7 +345,7 @@ describe('Dependency Resolution', () => {
|
|
|
333
345
|
resolved.push(dep);
|
|
334
346
|
} else {
|
|
335
347
|
// Mock registry fetch for other components
|
|
336
|
-
(global.fetch as
|
|
348
|
+
(global.fetch as unknown as Mock).mockResolvedValueOnce({
|
|
337
349
|
ok: true,
|
|
338
350
|
json: async () => ({
|
|
339
351
|
id: dep,
|
|
@@ -364,13 +376,13 @@ describe('Dependency Resolution', () => {
|
|
|
364
376
|
await registry.getComponent(dep);
|
|
365
377
|
resolved.push(dep);
|
|
366
378
|
} else if (dep === 'non-existent') {
|
|
367
|
-
(global.fetch as
|
|
379
|
+
(global.fetch as unknown as Mock).mockResolvedValueOnce({
|
|
368
380
|
ok: false,
|
|
369
381
|
status: 404,
|
|
370
382
|
});
|
|
371
383
|
await registry.getComponent(dep);
|
|
372
384
|
} else {
|
|
373
|
-
(global.fetch as
|
|
385
|
+
(global.fetch as unknown as Mock).mockResolvedValueOnce({
|
|
374
386
|
ok: true,
|
|
375
387
|
json: async () => ({
|
|
376
388
|
id: dep,
|
|
@@ -383,7 +395,7 @@ describe('Dependency Resolution', () => {
|
|
|
383
395
|
await registry.getComponent(dep);
|
|
384
396
|
resolved.push(dep);
|
|
385
397
|
}
|
|
386
|
-
} catch
|
|
398
|
+
} catch {
|
|
387
399
|
failed.push(dep);
|
|
388
400
|
}
|
|
389
401
|
}
|
|
@@ -556,10 +568,7 @@ import { cn } from "@foundrykit/utils";`;
|
|
|
556
568
|
type EmptyStateBehavior,
|
|
557
569
|
} from '@foundrykit/hooks';`;
|
|
558
570
|
|
|
559
|
-
const transformed = transformImportsForConfig(
|
|
560
|
-
source,
|
|
561
|
-
packageHooksConfig
|
|
562
|
-
);
|
|
571
|
+
const transformed = transformImportsForConfig(source, packageHooksConfig);
|
|
563
572
|
|
|
564
573
|
expect(transformed).toBe(source);
|
|
565
574
|
expect(transformed).not.toContain('@/hooks/use-advanced-search');
|