diff --git a/packages/cli/src/commands/diff.ts b/packages/cli/src/commands/diff.ts index 4675eb4b..4534f40f 100644 --- a/packages/cli/src/commands/diff.ts +++ b/packages/cli/src/commands/diff.ts @@ -99,7 +99,7 @@ export const diff = new Command() consola.info(` - ${change.filePath}`) } - console.log('') + consola.log('') consola.info( `Run ${colors.green('diff ')} to see the changes.`, ) @@ -128,7 +128,7 @@ export const diff = new Command() for (const change of changes) { consola.info(`- ${change.filePath}`) printDiff(change.patch) - console.log('') + consola.log('') } } catch (error) { diff --git a/packages/cli/src/commands/init.ts b/packages/cli/src/commands/init.ts index 3e9085a6..a70e7f7f 100644 --- a/packages/cli/src/commands/init.ts +++ b/packages/cli/src/commands/init.ts @@ -73,11 +73,11 @@ export const init = new Command() await runInit(cwd, config) - console.log('') + consola.log('') consola.info( `${colors.green('Success!')} Project initialization completed.`, ) - console.log('') + consola.log('') } catch (error) { handleError(error) @@ -206,7 +206,7 @@ export async function promptForConfig( } // Write to file. - console.log('') + consola.log('') const spinner = ora('Writing components.json...').start() const targetPath = path.resolve(cwd, 'components.json') await fs.writeFile(targetPath, JSON.stringify(config, null, 2), 'utf8') @@ -291,8 +291,8 @@ export async function runInit(cwd: string, config: Config) { await Promise.allSettled( [ - await addNuxtDevDeps(), - await addDependency(deps, { + addNuxtDevDeps(), + addDependency(deps, { cwd, silent: true, }), diff --git a/packages/cli/src/utils/get-config.ts b/packages/cli/src/utils/get-config.ts index aee851f5..d1b069a2 100644 --- a/packages/cli/src/utils/get-config.ts +++ b/packages/cli/src/utils/get-config.ts @@ -100,23 +100,21 @@ export async function resolveConfigPaths(cwd: string, config: RawConfig) { utils: resolveImport(config.aliases.utils, tsConfig), components: resolveImport(config.aliases.components, tsConfig), ui: config.aliases['ui'] - ? await resolveImport(config.aliases['ui'], tsConfig) - : await resolveImport(config.aliases['components'], tsConfig), + ? resolveImport(config.aliases['ui'], tsConfig) + : resolveImport(config.aliases['components'], tsConfig), }, }) } export async function getRawConfig(cwd: string): Promise { try { - // const configResult = await explorer.search(cwd) - const configResult = await c12LoadConfig({ name: 'components', configFile: 'components.json', cwd, }) - if (!configResult) + if (!configResult.config || Object.keys(configResult.config).length === 0) return null return rawConfigSchema.parse(configResult.config) diff --git a/packages/cli/test/commands/init.test.ts b/packages/cli/test/commands/init.test.ts index 32cbe0bd..a944f251 100644 --- a/packages/cli/test/commands/init.test.ts +++ b/packages/cli/test/commands/init.test.ts @@ -1,14 +1,13 @@ import fs from 'node:fs' import path from 'node:path' -import { execa } from 'execa' +import { addDependency, addDevDependency } from 'nypm' import { afterEach, expect, test, vi } from 'vitest' import { runInit } from '../../src/commands/init' import { getConfig } from '../../src/utils/get-config' -import * as getPackageManger from '../../src/utils/get-package-manager' import * as registry from '../../src/utils/registry' -vi.mock('execa') +vi.mock('nypm') vi.mock('fs/promises', () => ({ writeFile: vi.fn(), mkdir: vi.fn(), @@ -16,7 +15,6 @@ vi.mock('fs/promises', () => ({ vi.mock('ora') test('init config-full', async () => { - vi.spyOn(getPackageManger, 'getPackageManager').mockResolvedValue('pnpm') vi.spyOn(registry, 'getRegistryBaseColor').mockResolvedValue({ inlineColors: {}, cssVars: {}, @@ -67,10 +65,8 @@ test('init config-full', async () => { expect.stringContaining("import { type ClassValue, clsx } from 'clsx'"), 'utf8', ) - expect(execa).toHaveBeenCalledWith( - 'pnpm', + expect(addDependency).toHaveBeenCalledWith( [ - 'add', 'tailwindcss-animate', 'class-variance-authority', 'clsx', @@ -80,6 +76,7 @@ test('init config-full', async () => { ], { cwd: targetDir, + silent: true, }, ) @@ -88,7 +85,6 @@ test('init config-full', async () => { }) test('init config-partial', async () => { - vi.spyOn(getPackageManger, 'getPackageManager').mockResolvedValue('npm') vi.spyOn(registry, 'getRegistryBaseColor').mockResolvedValue({ inlineColors: {}, cssVars: {}, @@ -139,10 +135,8 @@ test('init config-partial', async () => { expect.stringContaining("import { type ClassValue, clsx } from 'clsx'"), 'utf8', ) - expect(execa).toHaveBeenCalledWith( - 'npm', + expect(addDependency).toHaveBeenCalledWith( [ - 'install', 'tailwindcss-animate', 'class-variance-authority', 'clsx', @@ -152,6 +146,7 @@ test('init config-partial', async () => { ], { cwd: targetDir, + silent: true, }, ) diff --git a/packages/cli/test/utils/apply-color-mapping.test.ts b/packages/cli/test/utils/apply-color-mapping.test.ts index 178ae573..1fb0de6a 100644 --- a/packages/cli/test/utils/apply-color-mapping.test.ts +++ b/packages/cli/test/utils/apply-color-mapping.test.ts @@ -64,7 +64,7 @@ describe('apply color mapping', async () => { input: 'text-destructive border-destructive/50 dark:border-destructive [&>svg]:text-destructive text-destructive', output: - 'text-red-500 border-red-500/50 dark:border-red-500 [&>svg]:text-red-500 text-red-500 dark:text-red-900 dark:border-red-900/50 dark:dark:border-red-900 dark:[&>svg]:text-red-900 dark:text-red-900', + 'text-red-500 border-red-500/50 dark:border-red-500 [&>svg]:text-red-500 dark:text-red-900 dark:border-red-900/50 dark:dark:border-red-900 dark:[&>svg]:text-red-900', }, { input: diff --git a/packages/cli/test/utils/get-config.test.ts b/packages/cli/test/utils/get-config.test.ts index f875f2b5..1b3621f5 100644 --- a/packages/cli/test/utils/get-config.test.ts +++ b/packages/cli/test/utils/get-config.test.ts @@ -71,6 +71,11 @@ test('get config', async () => { '../fixtures/config-partial', './components', ), + ui: path.resolve( + __dirname, + '../fixtures/config-partial', + './components', + ), utils: path.resolve( __dirname, '../fixtures/config-partial', @@ -111,6 +116,11 @@ test('get config', async () => { '../fixtures/config-full', './src/components', ), + ui: path.resolve( + __dirname, + '../fixtures/config-full', + './src/components', + ), utils: path.resolve( __dirname, '../fixtures/config-full', @@ -152,6 +162,11 @@ test('get config', async () => { '../fixtures/config-js', './components', ), + ui: path.resolve( + __dirname, + '../fixtures/config-js', + './components', + ), utils: path.resolve(__dirname, '../fixtures/config-js', './lib/utils'), }, }) diff --git a/packages/cli/test/utils/get-package-manager.test.ts b/packages/cli/test/utils/get-package-manager.test.ts deleted file mode 100644 index b8b516c6..00000000 --- a/packages/cli/test/utils/get-package-manager.test.ts +++ /dev/null @@ -1,26 +0,0 @@ -import path from 'node:path' -import { expect, test } from 'vitest' - -import { getPackageManager } from '../../src/utils/get-package-manager' - -test('get package manager', async () => { - expect( - await getPackageManager(path.resolve(__dirname, '../fixtures/project-yarn')), - ).toBe('yarn') - - expect( - await getPackageManager(path.resolve(__dirname, '../fixtures/project-npm')), - ).toBe('npm') - - expect( - await getPackageManager(path.resolve(__dirname, '../fixtures/project-pnpm')), - ).toBe('pnpm') - - expect( - await getPackageManager(path.resolve(__dirname, '../fixtures/project-bun')), - ).toBe('bun') - - expect( - await getPackageManager(path.resolve(__dirname, '../fixtures/next')), - ).toBe('pnpm') -})