feat(when): extend $when with stack/library/repo/bool matchers#83
Conversation
… everywhere - Fix circular dependency in when.ts via lazy require of __meta__ - Extend $when match to support: stack, library, repo, and `true` (any value present) - Remove filterInternalDeps / stripInternalDeps in favor of explicit $when conditions - Apply resolveConditionals to all packageJson accesses in package-json-generator - Move lucide-react from nextjs stack into shadcn library - Gate @repo/db in better-auth on turborepo + orm selection - Gate @repo/auth/@repo/db in trpc on turborepo + library/orm selection - Make eslint React/Next plugins conditional on stack presence
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
This PR extends the $when conditional system with new matchers for stack, library, repo type, and boolean matching, enabling more precise control over dependency inclusion based on template context. The refactoring eliminates post-processing dependency filtering in favor of explicit conditional declarations, making the codebase more maintainable and type-safe.
Changes:
- Extended
$whenwith four new matchers:stack(matches stacks across all apps),library(matches libraries across all apps),repo(matches repository type), andtrue(matches any truthy value for ProjectContext keys) - Fixed circular dependency between
when.tsand__meta__.tsusing lazyrequire()with type assertion - Removed
stripInternalDepsandfilterInternalDepsfunctions in favor of explicit$whenconditions in metadata - Applied
resolveConditionalsto allpackageJsonaccesses throughoutpackage-json-generator.ts - Made ESLint React plugins conditional on React-based stacks, moved
lucide-reactfrom nextjs stack to shadcn library, and made@repo/*dependencies conditional on turborepo mode
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| apps/cli/src/lib/when.ts | Implemented four new matchers (repo, stack, library, true), fixed circular dependency with lazy require |
| apps/cli/src/meta.ts | Applied new matchers to make lucide-react, ESLint plugins, and @repo/* dependencies conditional |
| apps/cli/src/lib/package-json-generator.ts | Removed filtering functions, applied resolveConditionals to all packageJson accesses, updated generatePackagePackageJson signature |
| apps/cli/tests/unit/lib/when.test.ts | Added comprehensive tests for all four new matchers (22 new tests) |
| apps/cli/tests/unit/lib/package-json-generator.test.ts | Added tests validating conditional ESLint plugins, lucide-react, and @repo/* dependencies |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
apps/cli/src/lib/when.ts
Outdated
| return addon?.compose ?? [selected]; | ||
| // Lazy import to break circular dependency with __meta__.ts | ||
| // eslint-disable-next-line @typescript-eslint/no-require-imports | ||
| const { META } = require('@/__meta__') as typeof import('@/__meta__'); |
| const dbAddon = META.project.database.options[ctx.project.database]; | ||
| if (dbAddon) { | ||
| merged = mergePackageJsonConfigs(merged, dbAddon.packageJson); | ||
| merged = mergePackageJsonConfigs(merged, resolveConditionals(dbAddon.packageJson, ctx)); |
There was a problem hiding this comment.
instead of using resolveConditionnals in the params each time, use it directly inside the function
- Remove expandSelection and lazy require from when.ts — no more circular dependency with __meta__.ts - Make composite linter matching explicit via array conditions in META (eslint-prettier → ['eslint', 'eslint-prettier']) instead of runtime expansion - Add mergeResolved(ctx, ...configs) helper in package-json-generator to encapsulate resolveConditionals + mergePackageJsonConfigs pattern
Summary
$whenwith new matchers:stack,library,repo, andtrue(any value present for ProjectContext keys)when.tsvia lazyrequireof__meta__filterInternalDeps/stripInternalDepsin favor of explicit$whenconditionsresolveConditionalsto allpackageJsonaccesses inpackage-json-generatorChanges
when.tsstack: StackName | StackName[]— matches if any app uses the given stack(s)library: string | string[]— matches if any app has the given libraryrepo: 'single' | 'turborepo'— matches the repo typetrueas value for ProjectContext keys — matches any truthy value (e.g.orm: true)__meta__.tslucide-reactmoved fromnextjsstack →shadcnlibrary (only included when shadcn is selected)better-auth[@repo/db]:$when({ repo: 'turborepo', orm: true }, '*')trpc[@repo/auth]:$when({ repo: 'turborepo', library: 'better-auth' }, '*')trpc[@repo/db]:$when({ repo: 'turborepo', orm: true }, '*')eslint-plugin-react(hooks)only fornextjs/tanstack-start/expo,@next/eslint-plugin-nextonly fornextjsTest plan
when.test.ts— 22 tests covering all new matcherspackage-json-generator.test.ts— 84 tests including new cases for hono-only ESLint, lucide-react conditionality, and explicit@repo/*conditions