@foundrykit/cli 1.0.14 → 1.0.16

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.
@@ -192,6 +192,12 @@ async function addSingleComponent(
192
192
  // Fetch dependency from registry
193
193
  const depData = await registry.getComponent(dep);
194
194
 
195
+ // Handle package dependencies (hooks, types) differently
196
+ if (['hooks', 'types'].includes(dep)) {
197
+ console.log(chalk.green(` ✓ ${dep} package is available`));
198
+ continue;
199
+ }
200
+
195
201
  // Check if dependency files already exist
196
202
  const hasExisting = await hasConflictingFiles(depData, options);
197
203
 
@@ -7,18 +7,12 @@ import fs from 'fs-extra';
7
7
  import path from 'path';
8
8
  import os from 'os';
9
9
  import chalk from 'chalk';
10
- import {
11
- DEFAULT_REGISTRY_URL,
12
- CACHE_DIR,
13
- CACHE_FILE,
14
- CACHE_TTL,
15
- } from './constants.js';
10
+ import { DEFAULT_REGISTRY_URL, CACHE_DIR, CACHE_TTL } from './constants.js';
16
11
  import type {
17
12
  ComponentMeta,
18
13
  ComponentData,
19
14
  RegistryIndex,
20
15
  RegistryComponent,
21
- RegistryError,
22
16
  LocalCache,
23
17
  CLIConfig,
24
18
  } from '@foundrykit/types';
@@ -97,6 +91,11 @@ export class RegistryService {
97
91
  * Fetch a specific component by ID
98
92
  */
99
93
  async getComponent(id: string): Promise<ComponentData> {
94
+ // Check if it's a special dependency first
95
+ if (this.isSpecialDependency(id)) {
96
+ return this.createSpecialDependency(id);
97
+ }
98
+
100
99
  try {
101
100
  const url = `${this.config.registryUrl}/registry/${id}`;
102
101
  console.log(chalk.gray(`Fetching component: ${url}`));
@@ -135,6 +134,117 @@ export class RegistryService {
135
134
  }
136
135
  }
137
136
 
137
+ /**
138
+ * Check if a dependency ID is a special dependency that should be handled locally
139
+ */
140
+ private isSpecialDependency(id: string): boolean {
141
+ const specialDependencies = [
142
+ 'utils',
143
+ 'lib',
144
+ 'helpers',
145
+ 'cn', // Utils aliases
146
+ 'hooks',
147
+ 'types', // Package dependencies
148
+ ];
149
+ return specialDependencies.includes(id);
150
+ }
151
+
152
+ /**
153
+ * Create a special dependency component data
154
+ */
155
+ private async createSpecialDependency(id: string): Promise<ComponentData> {
156
+ // Handle utils and its aliases
157
+ if (['utils', 'lib', 'helpers', 'cn'].includes(id)) {
158
+ return {
159
+ id: 'utils',
160
+ name: 'Utils',
161
+ description: 'Utility functions for className merging',
162
+ category: 'primitives',
163
+ files: [
164
+ {
165
+ path: 'lib/utils.ts',
166
+ content: `import { type ClassValue, clsx } from 'clsx';
167
+ import { twMerge } from 'tailwind-merge';
168
+
169
+ export function cn(...inputs: ClassValue[]) {
170
+ return twMerge(clsx(inputs));
171
+ }`,
172
+ type: 'util',
173
+ },
174
+ ],
175
+ registryDependencies: [],
176
+ packageDependencies: ['clsx', 'tailwind-merge'],
177
+ };
178
+ }
179
+
180
+ // Handle hooks package dependency
181
+ if (id === 'hooks') {
182
+ // Check if @foundrykit/hooks is already installed
183
+ const isInstalled = await this.isPackageInstalled('@foundrykit/hooks');
184
+ if (isInstalled) {
185
+ return {
186
+ id: 'hooks',
187
+ name: 'Hooks',
188
+ description: 'Custom React hooks package',
189
+ category: 'primitives',
190
+ files: [], // No files to install, it's a package
191
+ registryDependencies: [],
192
+ packageDependencies: ['@foundrykit/hooks'],
193
+ };
194
+ } else {
195
+ throw new Error(
196
+ 'Package "@foundrykit/hooks" is not installed. Please install it first: pnpm add @foundrykit/hooks'
197
+ );
198
+ }
199
+ }
200
+
201
+ // Handle types package dependency
202
+ if (id === 'types') {
203
+ // Check if @foundrykit/types is already installed
204
+ const isInstalled = await this.isPackageInstalled('@foundrykit/types');
205
+ if (isInstalled) {
206
+ return {
207
+ id: 'types',
208
+ name: 'Types',
209
+ description: 'TypeScript type definitions',
210
+ category: 'primitives',
211
+ files: [], // No files to install, it's a package
212
+ registryDependencies: [],
213
+ packageDependencies: ['@foundrykit/types'],
214
+ };
215
+ } else {
216
+ throw new Error(
217
+ 'Package "@foundrykit/types" is not installed. Please install it first: pnpm add @foundrykit/types'
218
+ );
219
+ }
220
+ }
221
+
222
+ throw new Error(`Unknown special dependency: ${id}`);
223
+ }
224
+
225
+ /**
226
+ * Check if a package is installed in the current project
227
+ */
228
+ private async isPackageInstalled(packageName: string): Promise<boolean> {
229
+ try {
230
+ const packageJsonPath = path.join(process.cwd(), 'package.json');
231
+ if (!(await fs.pathExists(packageJsonPath))) {
232
+ return false;
233
+ }
234
+
235
+ const packageJson = await fs.readJson(packageJsonPath);
236
+ const allDeps = {
237
+ ...packageJson.dependencies,
238
+ ...packageJson.devDependencies,
239
+ ...packageJson.peerDependencies,
240
+ };
241
+
242
+ return packageName in allDeps;
243
+ } catch (error) {
244
+ return false;
245
+ }
246
+ }
247
+
138
248
  /**
139
249
  * Update the local cache with new component list
140
250
  */