Skip to content

Commit dc204d1

Browse files
committed
feat: pre-install commonly-needed packages and add cn() utility to Vite React template
- Add nanoid, clsx, tailwind-merge to UNIVERSAL_EXTRA_PACKAGES - Add sonner, class-variance-authority, recharts to REACT_EXTRA_PACKAGES - Add vue-router, lucide-vue-next to VUE_EXTRA_PACKAGES - Add cn() utility (src/lib/utils.ts) to Vite React inline template - Add cn() utility path hint to template userMessage for LLM context - Prevents auto-fix loops from commonly-imported missing dependencies
1 parent 67d6585 commit dc204d1

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

app/utils/inline-templates.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@ ReactDOM.createRoot(document.getElementById('root')!).render(
139139
}
140140
141141
export default App;
142+
`,
143+
),
144+
f(
145+
'src/lib/utils.ts',
146+
`import { type ClassValue, clsx } from 'clsx';
147+
import { twMerge } from 'tailwind-merge';
148+
149+
export function cn(...inputs: ClassValue[]) {
150+
return twMerge(clsx(inputs));
151+
}
142152
`,
143153
),
144154
f(

app/utils/selectStarterTemplate.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ const UNIVERSAL_EXTRA_PACKAGES: Record<string, string> = {
6666
'date-fns': '^4.1.0',
6767
axios: '^1.7.9',
6868
zod: '^3.24.1',
69+
nanoid: '^5.1.5',
70+
clsx: '^2.1.1',
71+
'tailwind-merge': '^2.5.4',
6972
};
7073

7174
/**
@@ -81,6 +84,9 @@ const REACT_EXTRA_PACKAGES: Record<string, string> = {
8184
'@tanstack/react-query': '^5.62.16',
8285
'react-hook-form': '^7.54.2',
8386
'@hookform/resolvers': '^3.9.1',
87+
sonner: '^1.7.0',
88+
'class-variance-authority': '^0.7.0',
89+
recharts: '^2.15.0',
8490
};
8591

8692
/**
@@ -98,6 +104,8 @@ const COMMON_EXTRA_PACKAGES: Record<string, string> = {
98104
const VUE_EXTRA_PACKAGES: Record<string, string> = {
99105
pinia: '^3.0.1',
100106
'@vueuse/core': '^12.5.0',
107+
'vue-router': '^4.5.0',
108+
'lucide-vue-next': '^0.460.0',
101109
};
102110

103111
/**
@@ -831,10 +839,14 @@ ${resolvedName.toLowerCase().includes('shadcn') ? `- Shadcn/ui template: All Rad
831839
const filePaths = filteredFiles.map((f) => f.path);
832840
const mainEntryFile = entryPointPriority.find((ep) => filePaths.includes(ep));
833841

842+
// Detect cn() utility location so the LLM uses it instead of creating its own
843+
const cnUtilityPaths = ['src/lib/utils.ts', 'lib/utils.ts', 'src/utils.ts', 'utils/cn.ts'];
844+
const cnUtilityFile = cnUtilityPaths.find((p) => filePaths.includes(p));
845+
834846
userMessage += `
835847
Template "${displayName}" imported and running. All files are already created and installed — DO NOT recreate them.
836848
${archSummary ? `Architecture: ${archSummary}\n` : ''}${dirHint ? `Directories: ${dirHint}\n` : ''}Pre-installed packages (ready to import): ${availablePackageHint}.
837-
${mainEntryFile ? `Primary file to modify: ${mainEntryFile}\n` : ''}`;
849+
${mainEntryFile ? `Primary file to modify: ${mainEntryFile}\n` : ''}${cnUtilityFile ? `Class utility: import { cn } from '${cnUtilityFile.startsWith('src/') ? `@/${cnUtilityFile.slice(4, -3)}` : `./${cnUtilityFile.slice(0, -3)}`}' — use cn() for conditional class merging.\n` : ''}`;
838850

839851
/*
840852
* Add framework-specific coding hints for non-React frameworks

0 commit comments

Comments
 (0)