diff --git a/.changeset/floppy-lies-smoke.md b/.changeset/floppy-lies-smoke.md new file mode 100644 index 000000000..6ccc8eb35 --- /dev/null +++ b/.changeset/floppy-lies-smoke.md @@ -0,0 +1,5 @@ +--- +"shadcn": patch +--- + +fix handling of base styles for add command diff --git a/packages/shadcn/src/commands/add.ts b/packages/shadcn/src/commands/add.ts index 0c9850897..ebfb821a5 100644 --- a/packages/shadcn/src/commands/add.ts +++ b/packages/shadcn/src/commands/add.ts @@ -90,14 +90,20 @@ export const add = new Command() } let itemType: z.infer | undefined + let shouldInstallBaseStyle = true if (components.length > 0) { const [registryItem] = await getRegistryItems([components[0]], { config: initialConfig, }) itemType = registryItem?.type + shouldInstallBaseStyle = + itemType !== "registry:theme" && itemType !== "registry:style" if (isUniversalRegistryItem(registryItem)) { - await addComponents(components, initialConfig, options) + await addComponents(components, initialConfig, { + ...options, + baseStyle: shouldInstallBaseStyle, + }) return } @@ -170,11 +176,12 @@ export const add = new Command() force: true, defaults: false, skipPreflight: false, - silent: options.silent || !hasNewRegistries, + silent: options.silent && !hasNewRegistries, isNewProject: false, srcDir: options.srcDir, cssVariables: options.cssVariables, - baseStyle: itemType !== "registry:theme", + baseStyle: shouldInstallBaseStyle, + baseColor: shouldInstallBaseStyle ? undefined : "neutral", components: options.components, }) initHasRun = true @@ -209,7 +216,8 @@ export const add = new Command() isNewProject: true, srcDir: options.srcDir, cssVariables: options.cssVariables, - baseStyle: itemType !== "registry:theme", + baseStyle: shouldInstallBaseStyle, + baseColor: shouldInstallBaseStyle ? undefined : "neutral", components: options.components, }) initHasRun = true @@ -238,7 +246,7 @@ export const add = new Command() if (!initHasRun) { await addComponents(options.components, config, { ...options, - baseStyle: itemType !== "registry:theme", + baseStyle: shouldInstallBaseStyle, }) } diff --git a/packages/shadcn/src/commands/init.ts b/packages/shadcn/src/commands/init.ts index 2832c3297..219d87a89 100644 --- a/packages/shadcn/src/commands/init.ts +++ b/packages/shadcn/src/commands/init.ts @@ -26,6 +26,7 @@ import { DEFAULT_TAILWIND_CONFIG, DEFAULT_TAILWIND_CSS, DEFAULT_UTILS, + createConfig, getConfig, resolveConfigPaths, type Config, @@ -161,7 +162,13 @@ export const init = new Command() if (components.length > 0) { // We don't know the full config at this point. // So we'll use a shadow config to fetch the first item. - let shadowConfig = configWithDefaults({}) + let shadowConfig = configWithDefaults( + createConfig({ + resolvedPaths: { + cwd: options.cwd, + }, + }) + ) // Check if there's a components.json file. // If so, we'll merge with our shadow config. @@ -169,7 +176,18 @@ export const init = new Command() if (fsExtra.existsSync(componentsJsonPath)) { const existingConfig = await fsExtra.readJson(componentsJsonPath) const config = rawConfigSchema.partial().parse(existingConfig) - shadowConfig = configWithDefaults(config) + const baseConfig = createConfig({ + resolvedPaths: { + cwd: options.cwd, + }, + }) + shadowConfig = configWithDefaults({ + ...config, + resolvedPaths: { + ...baseConfig.resolvedPaths, + cwd: options.cwd, + }, + }) // Since components.json might not be valid at this point. // Temporarily rename components.json to allow preflight to run. @@ -183,6 +201,7 @@ export const init = new Command() shadowConfig, { silent: true, + writeFile: false, } ) shadowConfig = updatedConfig @@ -218,7 +237,7 @@ export const init = new Command() )} Project initialization completed.\nYou may now add components.` ) - // We need when runninng with custom cwd. + // We need when running with custom cwd. deleteFileBackup(path.resolve(options.cwd, "components.json")) logger.break() } catch (error) {