Skip to content

chore(cli): Convert to TS: yargsCommandHelpers, cedarPluralize, etc#764

Closed
Tobbe wants to merge 6 commits into
mainfrom
tobbe-chore-yargs-command-helpers-ts
Closed

chore(cli): Convert to TS: yargsCommandHelpers, cedarPluralize, etc#764
Tobbe wants to merge 6 commits into
mainfrom
tobbe-chore-yargs-command-helpers-ts

Conversation

@Tobbe
Copy link
Copy Markdown
Member

@Tobbe Tobbe commented Dec 21, 2025

Unfortunately have to close this PR

cedarPluralize is now a TS files. Typically in TS ESM projects you'd import it as './cedarPluralize.js' (or './cedarPluralize.ts' depending on your TS config). And this should work both when importing it from other TS files and also when importing it from a JS file. BUT Vitest doesn't support importing TS files from JS files, no matter what extension you use. This is a known issue with the version of Vite we're using. It's fixed in newer versions of Vite/Vitest
vitejs/vite#18889
vitest-dev/vitest#5999

@netlify
Copy link
Copy Markdown

netlify Bot commented Dec 21, 2025

Deploy Preview for cedarjs canceled.

Name Link
🔨 Latest commit 339102b
🔍 Latest deploy log https://app.netlify.com/projects/cedarjs/deploys/6948e35759132c000827aaf2

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Dec 21, 2025

Greptile Summary

This PR converts several CLI utility files from JavaScript to TypeScript, including renaming rwPluralize.js to cedarPluralize.ts. The conversion adds proper type annotations throughout, replacing JSDoc comments with TypeScript types and interfaces.

Key changes:

  • Renamed rwPluralize module to cedarPluralize across the codebase
  • Converted yargsCommandHelpers.js to TypeScript with proper yargs type imports (Argv, Options, PositionalOptions)
  • Converted helpers.js to TypeScript with DMMF types from @prisma/generator-helper
  • Converted pluralHelpers.js to TypeScript with typed interfaces for function options
  • Added @types/pluralize dev dependency for type support
  • Updated all import statements across handler files to reference the renamed module

Minor implementation note:
The lastWord function in cedarPluralize.ts was refactored from using optional chaining (capitals?.slice(-1)[0]) to explicit array access after a null check, which is functionally equivalent but slightly more explicit.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • Clean TypeScript conversion with proper type annotations, comprehensive test coverage remains intact, and all imports properly updated. The minor style suggestion in lastWord doesn't affect functionality.
  • No files require special attention

Important Files Changed

Filename Overview
packages/cli/src/lib/cedarPluralize.ts Converted from JS to TS with proper type annotations, minor logic change in lastWord function may affect edge cases
packages/cli/src/commands/generate/yargsCommandHelpers.ts Converted from JS to TS with proper yargs types, replaced JSDoc with TypeScript interfaces
packages/cli/src/lib/pluralHelpers.ts Clean conversion to TS with proper interface for options, type annotations on all functions
packages/cli/src/commands/generate/helpers.ts Converted to TS, imported DMMF types from Prisma, all function signatures properly typed
packages/cli/package.json Added @types/pluralize dev dependency to support TypeScript conversion

Sequence Diagram

sequenceDiagram
    participant Handler as Handler Files (JS)
    participant Helpers as helpers.ts
    participant YargsHelpers as yargsCommandHelpers.ts
    participant CedarPluralize as cedarPluralize.ts
    participant PluralHelpers as pluralHelpers.ts
    participant Pluralize as pluralize library

    Note over Handler,Pluralize: TypeScript Conversion Flow

    Handler->>YargsHelpers: Import createBuilder, createCommand
    YargsHelpers->>YargsHelpers: Apply yargs types (Argv, Options)
    
    Handler->>Helpers: Import pathName, validateName, etc.
    Helpers->>CedarPluralize: Import pluralize, isPlural, isSingular
    
    Handler->>CedarPluralize: Import pluralization functions
    Note over CedarPluralize: Renamed from rwPluralize.js
    
    CedarPluralize->>CedarPluralize: Type mappings as Record<string, string>
    CedarPluralize->>Pluralize: Call plurals.plural(word)
    Pluralize-->>CedarPluralize: Return pluralized word
    CedarPluralize-->>Handler: Return typed result
    
    Handler->>PluralHelpers: Import ensureUniquePlural
    PluralHelpers->>CedarPluralize: Call isPlural, isSingular
    PluralHelpers->>PluralHelpers: Validate with interface types
    PluralHelpers-->>Handler: Return validated plural
Loading

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

14 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment thread packages/cli/src/lib/cedarPluralize.ts
@github-actions github-actions Bot added this to the chore milestone Dec 21, 2025
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Dec 21, 2025

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit d65e7cb

Command Status Duration Result
nx run-many -t test --minWorkers=1 --maxWorkers=4 ❌ Failed 27s View ↗
nx run-many -t build:pack --exclude create-ceda... ✅ Succeeded 3s View ↗
nx run-many -t build ✅ Succeeded 2s View ↗
nx run-many -t test:types ✅ Succeeded 6s View ↗

☁️ Nx Cloud last updated this comment at 2025-12-21 17:11:20 UTC

@Tobbe
Copy link
Copy Markdown
Member Author

Tobbe commented Dec 22, 2025

Closing this until we've updated Vite and/or cedarPluralize is only imported from TS files

@Tobbe Tobbe closed this Dec 22, 2025
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.

1 participant