diff --git a/packages/cli/src/commands/init.ts b/packages/cli/src/commands/init.ts index bc69f2e3..aced2889 100644 --- a/packages/cli/src/commands/init.ts +++ b/packages/cli/src/commands/init.ts @@ -117,12 +117,6 @@ export async function promptForConfig( { title: 'Nuxt', value: 'nuxt' }, ], }, - { - type: 'text', - name: 'root', - message: `Where is your ${highlight('source code')} folder located`, - initial: (prev, values) => defaultConfig?.root ?? values.framework === 'nuxt' ? '.' : 'src', - }, { type: 'select', name: 'style', @@ -181,7 +175,6 @@ export async function promptForConfig( const config = rawConfigSchema.parse({ // $schema: 'https://ui.shadcn.com/schema.json', - root: options.root, style: options.style, typescript: options.typescript, framework: options.framework, diff --git a/packages/cli/src/utils/get-config.ts b/packages/cli/src/utils/get-config.ts index 151cbdd9..fc6530ed 100644 --- a/packages/cli/src/utils/get-config.ts +++ b/packages/cli/src/utils/get-config.ts @@ -23,7 +23,6 @@ const explorer = cosmiconfig('components', { export const rawConfigSchema = z .object({ $schema: z.string().optional(), - root: z.string(), style: z.string(), typescript: z.boolean().default(false), tailwind: z.object({ @@ -65,26 +64,31 @@ export async function getConfig(cwd: string) { export async function resolveConfigPaths(cwd: string, config: RawConfig) { let tsConfig: ConfigLoaderResult | undefined + let tsConfigPath = path.resolve( + cwd, + config.framework === 'nuxt' ? '.nuxt/tsconfig.json' : './tsconfig.json', + ) + if (config.typescript) { - const TSCONFIG_PATH = config.framework === 'nuxt' ? '.nuxt/tsconfig.json' : './tsconfig.json' - // Read tsconfig.json. - const tsconfigPath = path.resolve(cwd, TSCONFIG_PATH) - tsConfig = loadConfig(tsconfigPath) - + tsConfig = loadConfig(tsConfigPath) // In new Vue project, tsconfig has references to tsconfig.app.json, which is causing the path not resolving correctly // If no paths were found, try to load tsconfig.app.json. if ('paths' in tsConfig && Object.keys(tsConfig.paths).length === 0) { - const FALLBACK_TSCONFIG_PATH = path.resolve(cwd, './tsconfig.app.json') - if (existsSync(FALLBACK_TSCONFIG_PATH)) - tsConfig = loadConfig(FALLBACK_TSCONFIG_PATH) + tsConfigPath = path.resolve(cwd, './tsconfig.app.json') + if (existsSync(tsConfigPath)) + tsConfig = loadConfig(tsConfigPath) } + } + else { + tsConfigPath = path.resolve(cwd, './jsconfig.json') + tsConfig = loadConfig(tsConfigPath) + } - if (tsConfig.resultType === 'failed') { - throw new Error( - `Failed to load tsconfig.json. ${tsConfig.message ?? ''}`.trim(), - ) - } + if (tsConfig.resultType === 'failed') { + throw new Error( + `Failed to load ${tsConfigPath}. ${tsConfig.message ?? ''}`.trim(), + ) } return configSchema.parse({ @@ -92,8 +96,8 @@ export async function resolveConfigPaths(cwd: string, config: RawConfig) { resolvedPaths: { tailwindConfig: path.resolve(cwd, config.tailwind.config), tailwindCss: path.resolve(cwd, config.tailwind.css), - utils: tsConfig ? await resolveImport(config.aliases.utils, tsConfig) : config.aliases.utils, - components: tsConfig ? await resolveImport(config.aliases.components, tsConfig) : config.aliases.components, + utils: await resolveImport(config.aliases.utils, tsConfig), + components: await resolveImport(config.aliases.components, tsConfig), }, }) } diff --git a/packages/cli/src/utils/registry/index.ts b/packages/cli/src/utils/registry/index.ts index 5642b2e2..6d8a0962 100644 --- a/packages/cli/src/utils/registry/index.ts +++ b/packages/cli/src/utils/registry/index.ts @@ -1,4 +1,5 @@ import path from 'node:path' +import process from 'node:process' import { HttpsProxyAgent } from 'https-proxy-agent' import fetch from 'node-fetch' import type * as z from 'zod' @@ -129,7 +130,6 @@ export function getItemTargetPath( return null return path.join( - config.typescript ? '' : config.root, config.resolvedPaths[parent as keyof typeof config.resolvedPaths], type, ) diff --git a/packages/cli/src/utils/transformers/transform-sfc.ts b/packages/cli/src/utils/transformers/transform-sfc.ts index 2065a205..e65ae3c3 100644 --- a/packages/cli/src/utils/transformers/transform-sfc.ts +++ b/packages/cli/src/utils/transformers/transform-sfc.ts @@ -18,7 +18,7 @@ interface File { export async function transformSFC(file: File, config: Config) { let content = transformImport(file.content, config) - if (config.typescript) + if (!config.typescript) content = await transformByDetype(content, file.name) return content