Skip to content

feat(when): extend $when with stack/library/repo/bool matchers#83

Merged
plvo merged 2 commits intomainfrom
feat/when-conditional-deps
Feb 20, 2026
Merged

feat(when): extend $when with stack/library/repo/bool matchers#83
plvo merged 2 commits intomainfrom
feat/when-conditional-deps

Conversation

@plvo
Copy link
Copy Markdown
Owner

@plvo plvo commented Feb 20, 2026

Summary

  • Extend $when with new matchers: stack, library, repo, and true (any value present for ProjectContext keys)
  • Fix pre-existing circular dependency in when.ts via lazy require of __meta__
  • Remove filterInternalDeps / stripInternalDeps in favor of explicit $when conditions
  • Apply resolveConditionals to all packageJson accesses in package-json-generator

Changes

when.ts

  • stack: StackName | StackName[] — matches if any app uses the given stack(s)
  • library: string | string[] — matches if any app has the given library
  • repo: 'single' | 'turborepo' — matches the repo type
  • true as value for ProjectContext keys — matches any truthy value (e.g. orm: true)

__meta__.ts

  • lucide-react moved from nextjs stack → shadcn library (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 React/Next plugins conditional on stack: eslint-plugin-react(hooks) only for nextjs/tanstack-start/expo, @next/eslint-plugin-next only for nextjs

Test plan

  • when.test.ts — 22 tests covering all new matchers
  • package-json-generator.test.ts — 84 tests including new cases for hono-only ESLint, lucide-react conditionality, and explicit @repo/* conditions
  • Full suite: 354 tests pass

… 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
@vercel
Copy link
Copy Markdown

vercel bot commented Feb 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
create-faster-www Ready Ready Preview, Comment Feb 20, 2026 2:20pm

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 $when with four new matchers: stack (matches stacks across all apps), library (matches libraries across all apps), repo (matches repository type), and true (matches any truthy value for ProjectContext keys)
  • Fixed circular dependency between when.ts and __meta__.ts using lazy require() with type assertion
  • Removed stripInternalDeps and filterInternalDeps functions in favor of explicit $when conditions in metadata
  • Applied resolveConditionals to all packageJson accesses throughout package-json-generator.ts
  • Made ESLint React plugins conditional on React-based stacks, moved lucide-react from 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.

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__');
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

const dbAddon = META.project.database.options[ctx.project.database];
if (dbAddon) {
merged = mergePackageJsonConfigs(merged, dbAddon.packageJson);
merged = mergePackageJsonConfigs(merged, resolveConditionals(dbAddon.packageJson, ctx));
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@plvo plvo merged commit 4a1a188 into main Feb 20, 2026
4 checks passed
@plvo plvo deleted the feat/when-conditional-deps branch February 20, 2026 14:21
@github-actions github-actions bot mentioned this pull request Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants